checks: a check on a calculated field judges the value the write will store, not the payload's (#7544) - #7666
Open
NicoleNG18 wants to merge 2 commits into
Conversation
… store, not the payload's (eclipse-dirigible#7544) Cause: the generated controllers run validate() and repository.warnings() before save()/update(), while the calculatedOnCreate / calculatedOnUpdate assignments happen inside them. A check on a calculated field - soft (severity: warn) or refusing - compared whatever the caller sent: nothing on a create, a stale value on an edit. The issue's "issued more than 5 days after the tax event" warning never fired for a REST write. Change (option (a) of the issue): - The generated repository gains calculatedForCreate / calculatedForUpdate: a field copy of the submitted record carrying what the write computes for its calculated fields - on create after the authored defaults, on update after taking the system-owned fields from the stored row and recomputing the document totals, as update() does. Only the neutral Calc expressions are evaluated; a calculated action runs on the write alone. The submitted record is untouched (dropSystemOwnedOnCreate and save()/update() see what they always saw); an entity with nothing calculated gets itself back. - All three controllers (power / my / partner, create and both update branches) run validate(), validateReferences() and warnings() on that candidate row. - The assistant guide documents checks on calculated fields. Verified: IntentCalculatedFieldChecksIT (new; the issue's declaration plus a refusing compare on the same field: create, stale and omitted payloads on update, a negative delay refused) - answered 200 instead of 428 against the unfixed templates, green with the fix; IntentSoftWarningsIT, IntentCheckMessageI18nIT, IntentEmissionCoverageIT, ModelGenerationIT and the two controller template ITs (anchors updated to the candidate-row call) green on H2; ide-template (216) and engine-intent (1479) unit suites; formatter:validate with the cache wiped. Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
…file-wide count (eclipse-dirigible#7544) The checks' create-time candidate row (calculatedForCreate) applies the authored defaults as save() does, so the default literal now appears twice in the generated repository and the occurrence count failed the smoke gate. Assert what the test means instead: save() and calculatedForCreate() apply the default, update() and calculatedForUpdate() never do. Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
This branch has not been deployed
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.
Cause
The generated controllers run
validate()andrepository.warnings()beforesave()/update(), but thecalculatedOnCreate/calculatedOnUpdateassignments only happen inside those methods. A check on a calculated field, soft (severity: warn) or refusing, therefore compared whatever the caller sent: nothing on a create, a stale value on an edit. The issue's legally required "issued more than 5 days after the tax event" warning never fired for a REST write.Change
This implements option (a) of the issue: evaluate the calculated expressions on the candidate row before the checks read it.
calculatedForCreate/calculatedForUpdate. Each returns a field copy of the submitted record carrying what the write will compute for its calculated fields:save()does (templates: defaultValue is applied after calculatedOnCreate on a server-side create - a line without vatRate computes vat 0 #7104);update()does. So an expression likeBalance = Total - Paidreads the storedPaid, never the payload's.Calcexpressions are evaluated. AcalculatedAction*may mint or mutate state, so it still runs only on the write itself.dropSystemOwnedOnCreate,save()andupdate()see exactly what they saw before, and what is persisted is still computed by the repository. An entity with nothing calculated gets the record itself back.validate(),validateReferences()andwarnings()now run on that candidate row.Verification
IntentCalculatedFieldChecksIT(HTTP-only; generates, compiles and runs the issue's declaration, plus a refusing compare on the same calculated field):IntentSoftWarningsITIntentCheckMessageI18nITIntentEmissionCoverageIT(compiles and runs a broad generated model)ModelGenerationITvalidate(...)anchors now point at the candidate-row callmvn formatter:validatepasses after wiping the formatter cache.Not verified: the PostgreSQL leg.
Not in scope:
Writer, intent: a task form's editable write-back skips field validation - an over-long value dead-letters the job and strands the record #7552): they write throughupdateProperties, which never recomputes calculated fields. Theirvalidatetherefore already reads the calculated values that stay stored.save()/update(): they still run before the calculated assignments. This PR changes only what the controllers' checks read.Fixes #7544
🤖 Generated with Claude Code