Repository navigation
Conversation
The vulnerability details response listed advisories in whatever order the database returned them, so advisories sharing a document ID (for example a CSAF VEX and a CVE record) could swap between requests. Order them by document ID, then advisory type, then advisory UUID - the same tie-break consumers such as trustify-ui apply client-side. VulnerabilityContext::advisories gets the equivalent SQL ordering so the ingestor path is stable too. Implements TC-7641 Assisted-by: Claude Code
Reviewer's GuideImplementationSort assembled vulnerability advisory summaries by document ID, advisory type, and UUID so the response order is stable.
Apply the equivalent three-key ordering in the ingestor’s vulnerability-advisory query.
TestsAdd endpoint and service tests that check the exact advisory order for forward and reverse ingestion sequences.
Tips and commandsInteracting with Sourcery
Customizing Your ExperienceAccess your dashboard to:
Getting Help
|
There was a problem hiding this comment.
Hey - I've found 3 issues
Prompt for AI Agents
Please address the comments from this code review:
## Individual Comments
### Comment 1
<location path="modules/ingestor/src/graph/vulnerability/mod.rs" line_range="264" />
<code_context>
advisory_vulnerability::Column::VulnerabilityId.eq(self.vulnerability.id.clone()),
)
+ .order_by_asc(advisory::Column::DocumentId)
+ .order_by_asc(Expr::cust(r#""advisory"."labels" ->> 'type'"#))
+ .order_by_asc(advisory::Column::Id)
.all(connection)
</code_context>
<issue_to_address>
**Advisory sequences differ by path**
When linked advisories share a document ID and one lacks `labels.type` while another has a non-empty type, or an empty type that sorts before it by UUID, `VulnerabilityContext::advisories` orders SQL `NULL` after non-NULL values, while `advisory_type` maps a missing type to `""` and the response sort uses UUID for ties. The ingestor and API therefore return different advisory sequences.
Coalesce the SQL type key to `''` so both paths sort missing and empty types identically before the UUID tie-break.
Also at `modules/fundamental/src/vulnerability/model/details/vulnerability_advisory.rs:453`, `modules/fundamental/src/vulnerability/model/details/vulnerability_advisory.rs:458`, `modules/fundamental/src/vulnerability/model/details/vulnerability_advisory.rs:467-472`.
</issue_to_address>
### Comment 2
<location path="modules/ingestor/src/graph/vulnerability/mod.rs" line_range="263-264" />
<code_context>
.filter(
advisory_vulnerability::Column::VulnerabilityId.eq(self.vulnerability.id.clone()),
)
+ .order_by_asc(advisory::Column::DocumentId)
+ .order_by_asc(Expr::cust(r#""advisory"."labels" ->> 'type'"#))
+ .order_by_asc(advisory::Column::Id)
.all(connection)
</code_context>
<issue_to_address>
**Locale changes advisory order**
When the database uses a locale-aware collation and linked advisories have document IDs or type labels whose locale order differs from Rust's bytewise order, postgreSQL applies the database collation to these text sort keys, while the response sorter uses Rust string ordering. Under a locale-aware collation, advisories with document IDs or types whose ordering differs from bytewise order appear in a different sequence in the ingestor path than in the API response.
Apply `COLLATE "C"` to the SQL text sort keys so their ordering matches Rust string comparison.
</issue_to_address>
### Comment 3
<location path="modules/fundamental/src/vulnerability/endpoints/test.rs" line_range="716-726" />
<code_context>
+ .expect("advisories must be an array")
+ .iter()
+ .map(|advisory| {
+ (
+ advisory["document_id"]
+ .as_str()
+ .unwrap_or_default()
+ .to_string(),
+ advisory["labels"]["type"]
+ .as_str()
+ .unwrap_or_default()
+ .to_string(),
+ )
+ })
+ .collect();
+
</code_context>
<issue_to_address>
**UUID tie-break tests miss duplicates**
When two linked advisories have the same document ID and type, the endpoint and service tests compare only document ID and type, and their fixtures do not contain a repeated pair. Removing the UUID tie-break therefore still passes the tests, leaving callers without the tested ordering guarantee.
Add advisories with the same document ID and type to the fixtures, and include UUIDs in the collected values and assertions.
Also at `modules/fundamental/src/vulnerability/service/test.rs:1386-1411`.
</issue_to_address>Sourcery assessment
Approval pending. 3 findings to address first.
Blocking findings: modules/ingestor/src/graph/vulnerability/mod.rs:264, modules/ingestor/src/graph/vulnerability/mod.rs:264, modules/fundamental/src/vulnerability/endpoints/test.rs:726
| advisory_vulnerability::Column::VulnerabilityId.eq(self.vulnerability.id.clone()), | ||
| ) | ||
| .order_by_asc(advisory::Column::DocumentId) | ||
| .order_by_asc(Expr::cust(r#""advisory"."labels" ->> 'type'"#)) |
There was a problem hiding this comment.
🟡 Medium · Advisory sequences differ by path
When linked advisories share a document ID and one lacks labels.type while another has a non-empty type, or an empty type that sorts before it by UUID, VulnerabilityContext::advisories orders SQL NULL after non-NULL values, while advisory_type maps a missing type to "" and the response sort uses UUID for ties. The ingestor and API therefore return different advisory sequences.
Coalesce the SQL type key to '' so both paths sort missing and empty types identically before the UUID tie-break.
Also at modules/fundamental/src/vulnerability/model/details/vulnerability_advisory.rs:453, modules/fundamental/src/vulnerability/model/details/vulnerability_advisory.rs:458, modules/fundamental/src/vulnerability/model/details/vulnerability_advisory.rs:467-472.
Prompt for AI agents
In `modules/ingestor/src/graph/vulnerability/mod.rs` at line 264:
**Advisory sequences differ by path**
When linked advisories share a document ID and one lacks `labels.type` while another has a non-empty type, or an empty type that sorts before it by UUID, `VulnerabilityContext::advisories` orders SQL `NULL` after non-NULL values, while `advisory_type` maps a missing type to `""` and the response sort uses UUID for ties. The ingestor and API therefore return different advisory sequences.
Coalesce the SQL type key to `''` so both paths sort missing and empty types identically before the UUID tie-break.
Also at `modules/fundamental/src/vulnerability/model/details/vulnerability_advisory.rs:453`, `modules/fundamental/src/vulnerability/model/details/vulnerability_advisory.rs:458`, `modules/fundamental/src/vulnerability/model/details/vulnerability_advisory.rs:467-472`.| .order_by_asc(advisory::Column::DocumentId) | ||
| .order_by_asc(Expr::cust(r#""advisory"."labels" ->> 'type'"#)) |
There was a problem hiding this comment.
🟡 Medium · Locale changes advisory order
When the database uses a locale-aware collation and linked advisories have document IDs or type labels whose locale order differs from Rust's bytewise order, postgreSQL applies the database collation to these text sort keys, while the response sorter uses Rust string ordering. Under a locale-aware collation, advisories with document IDs or types whose ordering differs from bytewise order appear in a different sequence in the ingestor path than in the API response.
Apply COLLATE "C" to the SQL text sort keys so their ordering matches Rust string comparison.
Prompt for AI agents
In `modules/ingestor/src/graph/vulnerability/mod.rs` at lines 263-264:
**Locale changes advisory order**
When the database uses a locale-aware collation and linked advisories have document IDs or type labels whose locale order differs from Rust's bytewise order, postgreSQL applies the database collation to these text sort keys, while the response sorter uses Rust string ordering. Under a locale-aware collation, advisories with document IDs or types whose ordering differs from bytewise order appear in a different sequence in the ingestor path than in the API response.
Apply `COLLATE "C"` to the SQL text sort keys so their ordering matches Rust string comparison.| ( | ||
| advisory["document_id"] | ||
| .as_str() | ||
| .unwrap_or_default() | ||
| .to_string(), | ||
| advisory["labels"]["type"] | ||
| .as_str() | ||
| .unwrap_or_default() | ||
| .to_string(), | ||
| ) | ||
| }) |
There was a problem hiding this comment.
🟡 Medium · UUID tie-break tests miss duplicates
When two linked advisories have the same document ID and type, the endpoint and service tests compare only document ID and type, and their fixtures do not contain a repeated pair. Removing the UUID tie-break therefore still passes the tests, leaving callers without the tested ordering guarantee.
Add advisories with the same document ID and type to the fixtures, and include UUIDs in the collected values and assertions.
Also at modules/fundamental/src/vulnerability/service/test.rs:1386-1411.
Prompt for AI agents
In `modules/fundamental/src/vulnerability/endpoints/test.rs` at lines 716-726:
**UUID tie-break tests miss duplicates**
When two linked advisories have the same document ID and type, the endpoint and service tests compare only document ID and type, and their fixtures do not contain a repeated pair. Removing the UUID tie-break therefore still passes the tests, leaving callers without the tested ordering guarantee.
Add advisories with the same document ID and type to the fixtures, and include UUIDs in the collected values and assertions.
Also at `modules/fundamental/src/vulnerability/service/test.rs:1386-1411`.|
@ruromero, I'm not sure why this one was created prior the fix on the main branch ? |
Summary
Backport of #2900 to
release/0.7.zfor RHTPA 3.2.0 / stream 3.2.x.document_id, then advisory type (labels.type), then advisory UUID soGET /v3/vulnerability/{id}no longer depends on database row order.VulnerabilityContext::advisoriesin the ingestor so that path is stable too.document_id(different types) plus an unrelated advisory, asserting the exact sequence for both forward and reverse ingestion order.Notes
VulnerabilityAdvisorySummary::from_entities), which keeps the tie-break portable instead of relying on PostgreSQL JSON ordering. The ingestor query uses the same three keys as anORDER BY.AdvisoryInformationon this branch has nopublisher_namespacefield, so the new test helper does not set it.Implements TC-7641
Summary by Sourcery
Return vulnerability advisories in a stable, deterministic order across API and service paths.
Bug Fixes:
Tests: