Skip to content

fix(edit): Calculate Field's preview shows the value a calculation rule leaves in the field (#2884) - #2904

Merged
Mavrick-F merged 3 commits into
opengeos:mainfrom
choupeanut:fix/2884-preview-calculation-rules
Nov 25, 2026
Merged

Mavrick-F merged 3 commits into
opengeos:mainfrom
choupeanut:fix/2884-preview-calculation-rules

Conversation

@choupeanut

@choupeanut choupeanut commented Nov 25, 2026 •

Copy link
Copy Markdown
Contributor

Summary

Calculate Field's preview showed the expression's own result even when a calculation rule writes the same field and overwrites it on the run. preview_calculation ran the layer's calculation rules only to find a refusal and dropped their result, and ran them not at all for a layer with calculation rules and no checks.

It now takes the value from the one-row copy after calculation_rules (the function the run uses), and says what the last rule writing the field loses (WriteLosses::previewed). A rule on another field leaves the value and loss as they were. When a rule overwrites Calculate's result, the preview no longer shows what Calculate's own result lost; the run still says it in its notices. The docs paragraph on the preview (docs/user-guide/expressions.md) says so.

No new command, parameter or interface text, so no translation, command-surface or schema change. The dialog still previews only its PREVIEW_ROWS (3) rows. The one-row copy and the rules run only for a layer with a check or a calculation rule on the calculated field, since the dialog asks every frame; a layer with calculation rules on other fields only gets the expression's value, as before. The only caller is the Calculate Field dialog (also opened from the attribute table); a standalone table has no rules.

Testing

UI evidence

No layout or text change: the preview line and the dialog look as before, and only the value it shows differs when a rule writes the field, so there is no screenshot.

Related issue

Closes #2884

Summary by CodeRabbit

  • Bug Fixes

    • Calculate Field previews now reflect calculation rules that write to the selected field, including the final value after later rules and any resulting losses.
    • Preview loss reporting now prioritizes expression errors, unheld results, and numeric or date cuts in that order.
    • Rules that target other fields no longer affect the preview.
  • Documentation

    • Clarified how previews handle calculation rules, overwritten results, and rules that can no longer be read.

@coderabbitai

coderabbitai Bot commented Nov 25, 2026 •

Copy link
Copy Markdown
Contributor

Explain Change →

No actionable comments were generated in the recent review.

Walkthrough

The Calculate Field preview now simulates calculation rules that write the target field. It shows the final field value and its write loss, then applies layer refusal checks to that value. Rules on other fields alone do not trigger row simulation.

Changes: Calculate Field preview

Layer / File(s) Summary
Preview write-loss ordering and checks
crates/engine/src/cmd/edit.rs
WriteLosses::previewed reports the first expression error or present loss in the defined order. Tests compare its output with losses derived from held values.
Rule simulation and preview output
crates/engine/src/cmd/edit.rs, crates/engine/src/tests.rs, docs/user-guide/expressions.md
When calculation rules write the target field, the preview shows the value and loss from the last writing rule and applies refusal checks to that value. Tests and documentation cover overwrite order, skipped unreadable rules, and other preview cases.

Estimated code review effort: 3 (Moderate) | ~20 minutes

Change: Bug fix · Severity of issue fixed: Medium

Sequence Diagram(s)

sequenceDiagram
  participant CalculateFieldPreview
  participant CalculationRules
  participant LayerRefusalChecks
  CalculateFieldPreview->>CalculationRules: simulate rules that write the target field
  CalculationRules-->>CalculateFieldPreview: return final field value and write loss
  CalculateFieldPreview->>LayerRefusalChecks: check the final field value
  LayerRefusalChecks-->>CalculateFieldPreview: return refusal result
Loading

Possibly related PRs

  • opengeos/RustGIS#2822: Adds the live Calculate Field preview whose output contract this change updates.
  • opengeos/RustGIS#2873: Extends the same preview with layer refusal checks, which this change applies to the final rule-written value.

Suggested reviewers: jgregoriorincon

Merge Risk: Minimal · up to 12ef1

The Calculate Field preview now shows the value a calculation rule leaves in the field, and the documentation is updated to match. No merge-blocking risk was found in this change.

Pre-merge checks: Passed 4

Check name Status Explanation
Title check Passed The title names the fix and the feature it changes: Calculate Field's preview now shows the value a calculation rule leaves in the field. This matches the main change in the summary, which changes pre…
Description check Passed The description follows the template sections: Summary, Testing, UI evidence, and Related issue. The Summary explains the bug, the fix, and the narrower scope. Testing lists the new engine tests, the …
Linked Issues check Passed [#2884] The issue asks that, when a calculation rule writes the calculated field, the Calculate Field preview show the value the field holds after the rules run, with what that write loses. The PR des…
Out of Scope Changes check Passed The changes fall within the scope of #2884. The edit.rs change adjusts the preview value and loss for same-field calculation rules, and the WriteLosses::previewed ordering (expression error, unheld re…
Full details: Title check

Explanation

The title names the fix and the feature it changes: Calculate Field's preview now shows the value a calculation rule leaves in the field. This matches the main change in the summary, which changes preview_calculation to use the one-row copy after calculation_rules, and the linked issue #2884. The title is specific and concise, and the 99-character length is acceptable.

Full details: Description check

Explanation

The description follows the template sections: Summary, Testing, UI evidence, and Related issue. The Summary explains the bug, the fix, and the narrower scope. Testing lists the new engine tests, the commands run, and the checks not run locally. UI evidence states there is no visible UI change, which the template allows. Related issue reads Closes #2884. The description is thorough and complete.

Full details: Linked Issues check

Explanation

[#2884] The issue asks that, when a calculation rule writes the calculated field, the Calculate Field preview show the value the field holds after the rules run, with what that write loses. The PR description and the change summary state that preview_calculation now simulates the calculation rules that write the requested field. It takes the value from a one-row copy after calculation_rules, the same path the run uses, and reports the loss of the last rule that writes the field (WriteLosses::previewed). The new test calculate_field_preview_shows_what_a_calculation_rule_leaves_in_the_field compares the preview row by row with edit.calculateField across rule cases, including a rule that overwrites Calculate's result, a rule on another field, and a refusal from a domain. The raw diff of crates/engine/src/cmd/edit.rs could not be read in full (output truncated), so the function-level behavior rests on the summary and the test description, not on a direct read of the preview_calculation code. The evidence still supports the requirement. No coding requirement from #2884 is unmet in the stated evidence.

Full details: Out of Scope Changes check

Explanation

The changes fall within the scope of #2884. The edit.rs change adjusts the preview value and loss for same-field calculation rules, and the WriteLosses::previewed ordering (expression error, unheld result, then numeric/date cut) belongs to the same loss reporting the preview uses. The second test, a_losses_tally_previews_as_the_result_it_counts, checks that this tally matches Loss::previewed. The tests cover the changed behavior. The docs/user-guide/expressions.md change describes the new preview semantics. The PR states no command, parameter, interface text, translation, or schema change. The raw edit.rs diff was truncated, so the exact contents of the loss-ordering change were not read directly. Nothing in the available evidence shows an unrelated change.

Finishing Touches

Generate unit tests (beta)

  • Create a new PR
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

Share

A rabbit checks the field preview bright,
The last rule’s value comes to light.
Losses line up in their proper place,
Refusal checks now follow the trace.
I nibble clover, pleased and spry,
Then hop beneath the moonlit sky.

Recent review info

Run configuration

  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: Organization UI
  • Review profile: ASSERTIVE
  • Plan: Advanced
  • Run ID: 41d6dcfd-8805-4f6d-a833-2a6356ee637c
Commits

Reviewing files that changed from the base of the PR and between f5cf513 and 12ef1af.

Files selected for processing: 3

  • crates/engine/src/cmd/edit.rs
  • crates/engine/src/tests.rs
  • docs/user-guide/expressions.md

Included review availability: This review used your included allowance. Your plan provides up to 8 included reviews per hour; 6 remain after this review.

@github-actions

Copy link
Copy Markdown
Contributor

Code review

I found no bugs, security problems or AGENTS.md breaks. The rule-first preview matches what edit.calculateField leaves in the field. I checked the rule order, the @row_number offset, the field-index matching, the Features sharing, and that the new production code has no unwrap/expect. No prior review threads existed, so nothing was deduplicated.

Bugs: None found.

Security: None found.

Performance: None worth raising. The dialog re-runs the preview each frame for a layer with a calculation rule on the field. That now also parses the rules and clones the layer's field list for up to 3 rows. The cost is small, but it is new work on every frame. Confidence: low.

Quality:

  • Inline nit on crates/engine/src/cmd/edit.rs:2086 (test a_losses_tally_previews_as_the_result_it_counts): the local held shadows the held function, and result is cloned twice. The suggestion renames the binding and drops one clone. Confidence: high.
  • Design note, not posted inline: when a calculation rule overwrites the field, the preview shows only the rule's loss. Calculate's own loss is hidden, though the run still notifies, and the docs say so. This matches the stated intent. Confidence: moderate that it is intended.

AGENTS.md: None found. The PR adds no command, parameter or interface text, so the command-surface, schema, translation and surface rules do not apply.

Change size

Compared with the base branch (merge base 23e0f14 to PR head 12ef1af). The comparison covers the whole PR, not only the latest push.

Measure Value
Files changed 3 (0 added, 3 modified, 0 removed, 0 renamed)
Size before 3.68 MB
Size after 3.69 MB
Total size change +11.0 KB
Path Before After Change
crates/engine/src/tests.rs 3.53 MB 3.54 MB +6.6 KB
crates/engine/src/cmd/edit.rs 126.8 KB 130.9 KB +4.1 KB
docs/user-guide/expressions.md 21.3 KB 21.7 KB +356 B

@github-actions

Copy link
Copy Markdown
Contributor

📖 Docs preview

Commit 12ef1af from a fork built, but isn't published until a maintainer adds the preview label (once per commit).

@Mavrick-F
Mavrick-F added this pull request to the merge queue Nov 25, 2026
Merged via the queue into opengeos:main with commit f63cc72 Nov 25, 2026
28 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Calculate Field's preview shows the expression's value when a calculation rule writes the same field

2 participants