Skip to content

fix(layout): refuse a table or chart layer, field or rows value of the wrong type - #3196

Merged
jgregoriorincon merged 2 commits into
opengeos:mainfrom
jgregoriorincon:fix/3180-table-chart-typed-values
Nov 28, 2026
Merged

jgregoriorincon merged 2 commits into
opengeos:mainfrom
jgregoriorincon:fix/3180-table-chart-typed-values

Conversation

@jgregoriorincon

@jgregoriorincon jgregoriorincon commented Nov 28, 2026 •

Copy link
Copy Markdown
Contributor

Summary

layout.addElement and layout.update now refuse a table's or chart's layer, a chart's field or a table's rows given with a value of the wrong type, naming the key, with nothing changed. Before, a new table or chart took the first feature layer, the first numeric field or 12 rows, and an update kept what the element had.

  • layer and field take text, read with the given_name helper the other layout names use. frame_layer_name and checked_update cover both commands and their input binding.
  • rows takes a whole number of 0 or more, read as other layout numbers are, so "5" and 5.0 now mean 5 (they were ignored). 0 is still held to 1 and a number over 500 to 500; one with a fraction or below 0 is refused.
  • null still means not given, and a table still ignores field.

Surfaces: the two commands are shared, so the refusal reaches scripts, the command line, Python, the Assistant and MCP, plugins, and the desktop, browser and touch builds. The ribbon and the element pane send valid values, so nothing changes there. No option is added, so no tool description changes, and a refused call leaves no undo step.

Testing

New tests in crates/engine/src/tests/layout_typed_values.rs: wrong values are refused on add and update with the project and undo unchanged; null is not given, whole numbers (as text too) are taken, 0 and 900 rows are held to the range, and a chart keeps its own messages for an unknown field. Both failed before the fix. cargo fmt, clippy, nextest, doctests, the layer check and the schema check passed.

UI evidence

No visible UI change.

Related issue

Closes #3180.

Summary by CodeRabbit

  • Bug Fixes
    • Table row counts now default to 12 when omitted or null. Accepted whole-number values are limited to 1–500; invalid values return an error.
    • Invalid layer names and chart field values are now handled consistently when adding or updating layouts, with clear errors for missing or invalid selections. Existing elements remain unchanged when an update value is null.

@coderabbitai

coderabbitai Bot commented Nov 28, 2026 •

Copy link
Copy Markdown
Contributor

Explain Change →

No actionable comments were generated in the recent review.

Walkthrough

Layout commands now validate table row counts and table or chart layer and field values when adding or updating elements. Tests cover invalid and null values, row-count defaults and limits, and chart field errors.

Changes: Layout option validation

Layer / File(s) Summary
Add-element option parsing
crates/engine/src/cmd/layout/elements.rs, crates/engine/src/cmd/layout/inputs.rs
Table creation accepts nonnegative whole-number row counts, clamps them to 1–500, and defaults absent or null values to 12. Layer and chart field names use given_name.
Update validation and behavior tests
crates/engine/src/cmd/layout/update.rs, crates/engine/src/tests/layout_typed_values.rs
Table updates parse row counts before mutation. Table and chart layer names and chart field names use given_name. Tests cover invalid values, null values, row-count defaults and limits, and distinct chart field errors on add and update.

Estimated code review effort: 2 (Simple) | ~12 minutes

Change: Bug fix · Severity of issue fixed: Low

Suggested reviewers: elpidioassinaturas, m-hollis-1

Merge Risk: Minimal · up to b4135

Layout add and update commands now refuse wrong-typed table and chart values instead of silently falling back, and they leave the project unchanged on refusal. No actionable merge-blocking risk remains.

Pre-merge checks: Passed 4

Check name Status Explanation
Title check Passed The title names the main change: layout add and update commands now refuse table or chart layer, field, or rows values of the wrong type. It matches the changeset in elements.rs, inputs.rs, update.rs,…
Description check Passed The description follows the template sections: Summary, Testing, UI evidence, and Related issue. The UI evidence section keeps the 'No visible UI change.' line as the template requires. The Summary ex…
Linked Issues check Passed [#3180] The issue requires refusal of wrong-typed table or chart values on add and update, with the key named and nothing changed. The change covers each case. frame_layer_name in inputs.rs reads `l…
Out of Scope Changes check Passed All changed files serve the objective of #3180. elements.rs adds table_rows and switches chart field reading to given_name. inputs.rs and update.rs switch layer and field reading to given_name a…
Full details: Title check

Explanation

The title names the main change: layout add and update commands now refuse table or chart layer, field, or rows values of the wrong type. It matches the changeset in elements.rs, inputs.rs, update.rs, and the new tests. The title is specific and uses the conventional fix(layout) prefix.

Full details: Description check

Explanation

The description follows the template sections: Summary, Testing, UI evidence, and Related issue. The UI evidence section keeps the 'No visible UI change.' line as the template requires. The Summary explains the change and reasoning, the Testing section lists the new tests and checks run, and the Related issue section names #3180. The description is mostly complete.

Full details: Linked Issues check

Explanation

[#3180] The issue requires refusal of wrong-typed table or chart values on add and update, with the key named and nothing changed. The change covers each case. frame_layer_name in inputs.rs reads layer through given_name, so a non-text layer is refused instead of falling back to the first feature layer. Chart field in elements.rs and update.rs uses given_name, so a non-text field is refused instead of falling back to the first numeric field. table_rows in elements.rs refuses non-numeric, fractional, or negative rows, so a value is no longer replaced by 12. On update, the same parsing runs before mutation, so the existing value is no longer kept silently. The new tests in layout_typed_values.rs cover refusal on add and update with project and undo unchanged. The PR accepts whole-number text such as "5" and the value 5.0 as 5. The issue does not forbid this. It matches how other layout numbers are read. Rows 0 to 500 keep the existing clamping. The evidence comes from the PR summary and the stated test coverage. I did not inspect the code directly, so the result rests on that summary.

Full details: Out of Scope Changes check

Explanation

All changed files serve the objective of #3180. elements.rs adds table_rows and switches chart field reading to given_name. inputs.rs and update.rs switch layer and field reading to given_name and parse rows before mutation. layout_typed_values.rs holds tests for these paths. The PR adds no new option and no tool-description change. Clamping of rows to 1 to 500 and the default of 12 keep their existing behavior, so they stay within scope. The PR summary describes no unrelated edits. This verdict rests on the summary and the listed files, not on a full diff read.

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 rows with care,
And names the fields that should be there.
Null leaves the layout as it stood,
While valid counts stay in their bounds.
The chart and table hop along.

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: 988365d1-3446-4499-9a34-aab58ebcebf3
Commits

Reviewing files that changed from the base of the PR and between 9b0f0f9 and b41351c.

Files selected for processing: 4

  • crates/engine/src/cmd/layout/elements.rs
  • crates/engine/src/cmd/layout/inputs.rs
  • crates/engine/src/cmd/layout/update.rs
  • crates/engine/src/tests/layout_typed_values.rs

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

@github-actions

Copy link
Copy Markdown
Contributor

Code review

I read the four changed files, the helpers they call (given_name, given_num, ps, chart_options, chart_update), every caller of frame_layer_name and checked_update, and the new tests. I found no bugs or security problems. I could not build or run the tests here (no shell), so the findings below come from reading the code.

Bugs: None found.

  • Every wrong-type check runs before any mutation: table_rows and checked_update run before the element changes, and the refusal tests check that the project and Undo are unchanged.
  • frame_layer_name has three callers (the table and chart add paths, and the input binding). All of them are table or chart paths, so the stricter layer check does not reach other element kinds.
  • update_inputs calls checked_update with the same parameters, so binding and execution refuse the same values.
  • For a chart, the lenient reads in checked_update (statistic, group) cannot cause a silent change. chart_options refuses a wrong type on both paths, and chart_update runs it before any mutation.
  • No unwrap, expect or unsafe in non-test code. The new test helper uses unwrap, which is allowed in tests.

Security: None found.

Performance: None found.

Quality:

  • The silent clamp to 1–500 in table_rows (elements.rs:59) is posted as an inline comment. It is kept from before the PR, so it is a question, not a blocker. Confidence: low.
  • Nit: the doc comment on with_data() (layout_typed_values.rs) says "[laid_out], with a table and a chart too: their ids." The function also returns the session, so the comment should say so.
  • Nit: the comment above the rows values in a_table_or_chart_layer_field_or_rows_of_the_wrong_type_is_refused ("ones that aren't whole or are below 0 stand in for it, and so does text") is hard to follow. Reword it to say which values are refused and why.
  • Nit: the PR body's "limited to 1–500" wording (from the generated summary) is inaccurate. The code accepts 0 and 900 and clamps them to 1 and 500.

AGENTS.md: No breaks found.

  • Tests cover both the refused and the clean case, and refusals are checked for no project change and no Undo step.
  • No command or parameter is added or renamed, so command-surface.txt needs no update.
  • The saved-project schema does not change.
  • The engine is shared code with no cfg branch, so the wasm build is not affected.
  • The PR's surfaces note is consistent with the change.

Twins checked: frame_layer_name (all three callers); checked_update and update_inputs; the chart's label, group, statistic and field paths in chart_options; the colorbar layer reads, which already use given_name. The only other rows clamp is the load-time normalisation in crates/map/src/layout.rs:632, which is unchanged.

Prior reviews: There are no earlier threads on this PR, so no concerns were skipped.

Change size

Compared: the whole PR against main (merge base d9ae54e to PR head b41351c).

Measure Value
Files changed 4 (added 0, modified 4, removed 0, renamed 0)
Size before 116.4 KB
Size after 120.6 KB
Total size change +4.2 KB
Path Before After Change
crates/engine/src/tests/layout_typed_values.rs 8.9 KB 12.1 KB +3.2 KB
crates/engine/src/cmd/layout/update.rs 40.5 KB 41.0 KB +543 B
crates/engine/src/cmd/layout/elements.rs 52.9 KB 53.4 KB +459 B
crates/engine/src/cmd/layout/inputs.rs 14.1 KB 14.1 KB +35 B

@github-actions

Copy link
Copy Markdown
Contributor

📖 Docs preview

Item Value
Preview https://preview.rustgis.app/pr-3196/
Web app https://preview.rustgis.app/pr-3196/app/
Commit b41351c

GitHub Pages takes a minute or two to publish a new commit. Newer commits from the fork aren't published until a maintainer adds the preview label (once per commit).

@jgregoriorincon
jgregoriorincon added this pull request to the merge queue Nov 28, 2026
Merged via the queue into opengeos:main with commit ef1afb8 Nov 28, 2026
28 checks passed
@jgregoriorincon
jgregoriorincon deleted the fix/3180-table-chart-typed-values branch November 28, 2026 09:55
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.

[Bug]: Layout commands ignore a table's or chart's layer, field or rows of the wrong type without a word

1 participant