Repository navigation
fix: store ScanResult.language as text instead of an enum ordinal - #346
Merged
Merged
Conversation
`ScanResult.language` was an unannotated enum, so Hibernate stored it as an ordinal and generated a check constraint listing the languages that existed when the table was created. Databases created while `Language` had only JAVA and PYTHON still carry `CHECK (language >= 0 AND language <= 1)`, and `schema-management.strategy=update` never rewrites a check constraint, so inserting GO (ordinal 2) fails. This broke every scan, not just Go repositories: a ScanResult is written whenever the CBOM is non-null and the Go scanner returns an empty CBOM even with zero Go projects, so the whole transaction rolled back with the Java and Python results in it. `ScanRepository.save` swallowed the exception, so the scan still reported success over the WebSocket while ScanFinishedEvent was never emitted and nothing reached the read model. `@Enumerated(STRING)` would not fix this: the constraint comes from `EnumJavaType#getCheckCondition`, which fires for any enum typed attribute including ones mapped through an AttributeConverter. Only a non-enum Java type keeps the set of languages out of the schema. - map the column as String holding Language.name() - skip unknown language names in Scan#asAggregate with a warning instead of failing to reconstruct the whole aggregate - let ScanRepository#save throw AggregatePersistenceFailed so the process manager dispatches an ERROR instead of reporting success - add a round-trip test over Language.values(), so a language added to cbomkit-lib fails the build rather than production - ship the one-off migration, which update cannot apply, in migrations/ Refs #345
san-zrl
approved these changes
Sep 4, 2026
san-zrl
left a comment
Contributor
There was a problem hiding this comment.
Tx for spotting this. LGTM.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #345.
Problem
ScanResult.languagewas an unannotated enum, so Hibernate stored it as an ordinal and generated a check constraint listing the languages that existed when the table was created. Databases created whileLanguagehad onlyJAVA(0)/PYTHON(1)still carryCHECK (language >= 0 AND language <= 1), andschema-management.strategy=updatenever rewrites a check constraint — so insertingGO(ordinal 2) fails.This broke every scan, not just Go repositories: a
ScanResultis written whenever the CBOM is non-null, and the Go scanner returns an empty CBOM even with zero Go projects, so the single transaction rolled back with the Java and Python results in it.ScanRepository.saveswallowed the exception, so the scan still reported success over the WebSocket whileScanFinishedEventwas never emitted and nothing reached the read model.Why not
@Enumerated(EnumType.STRING)It does not help. The constraint is emitted by
EnumJavaType#getCheckCondition, keyed on the attribute's domain type being an enum rather than on the storage strategy — it would simply becomecheck (language in ('JAVA','PYTHON','GO'))and break again on the next language. ItsrenderConvertedEnumCheckConstraintmethod means anAttributeConverterdoes not escape it either, andAvailableSettingshas no global off-switch. Only a non-enum Java type keeps the set of languages out of the schema.Changes
StringholdingLanguage.name(), with a comment recording why it must not be "cleaned up" back into an enumScan#asAggregatewith a warning, so a language removed upstream cannot make stored scans unreadableScanRepository#savethrowAggregatePersistenceFailedinstead of swallowing failures, soScanProcessManagerdispatches anERRORrather than reporting success. Every call site is already inside a try that dispatchesERROR, compensates and rethrows, so no changes were needed thereLanguage.values(), so a language added to cbomkit-lib fails the build rather than productionmigrations/, referenced from the READMEMigration required
updatecannot alter a column type or drop a constraint, somigrations/2026-08-17-scanresult-language-as-text.sqlmust be run once against every database created before Go support. Databases created after this change need nothing.Verification
DomainTestCHECK (language IN ('JAVA','PYTHON'))) it errors. That run also confirmed thesavechange — it surfaced as an error propagating out ofsave, not a silent assertion failureScanningResourceTestpersisted aGOrow (JAVA 74→75, PYTHON 72→73) against a migrated database — the exact insert that was failingDeliberately out of scope
readanddeletestill swallow exceptions;read's empty-Optionalcontract is load-bearing for callersScanProcessManagerstill persists aScanResultfor an empty CBOM. Skipping empty results would have masked this bug rather than fixed it, so it is worth considering separatelyupdatecannot deploy constraint or column-type changes at all, so every future schema change needs a script like this one and a release note. Left for a separate discussion ([BUG] Stale scanresult_language_check constraint breaks all scans on pre-Go databases #345)