[BUG] Divisions: allow both is_land and is_territorial to be true#546
[BUG] Divisions: allow both is_land and is_territorial to be true#546Alex Iannicelli (atiannicelli) wants to merge 6 commits into
Conversation
Replace @radio_group (exactly one must be true) with a new @require_any_true constraint (at least one must be true) on DivisionArea and DivisionBoundary models. Changes: - Add require_any_true constraint to overture-schema-system - Update division_area.py and division_boundary.py to use it - Change division_boundary.yaml schema from oneOf to anyOf - Remove bad-not-both counterexample (now valid) - Add both_land_territorial positive examples - Update codegen model_constraints.py for new constraint type - Regenerate baseline schemas Closes #542 Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> Signed-off-by: Alex Iannicelli <atiannicelli@gmail.com>
🗺️ Schema reference docs preview is live!
Note ♻️ This preview updates automatically with each push to this PR. |
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> Signed-off-by: Alex Iannicelli <atiannicelli@gmail.com>
There was a problem hiding this comment.
Pull request overview
This PR updates the divisions schema to allow is_land and is_territorial to both be true by replacing the “exactly one true” constraint (@radio_group / oneOf) with an “at least one true” constraint (@require_any_true / anyOf) across the Pydantic models and the hand-written YAML schema.
Changes:
- Add a new
@require_any_truemodel constraint inoverture-schema-systemand export it. - Update
DivisionArea/DivisionBoundaryto use@require_any_true("is_land", "is_territorial"). - Update the YAML + baseline JSON schemas and examples/counterexamples to reflect
anyOfbehavior and allow both flags to betrue.
Reviewed changes
Copilot reviewed 11 out of 12 changed files in this pull request and generated 3 comments.
Show a summary per file
| File | Description |
|---|---|
| schema/divisions/division_boundary.yaml | Switches oneOf → anyOf for land/territorial flags in the YAML schema. |
| packages/overture-schema-system/src/overture/schema/system/model_constraint/require_any_true.py | Introduces the new model constraint and JSON Schema generation hook. |
| packages/overture-schema-system/src/overture/schema/system/model_constraint/init.py | Exports require_any_true / RequireAnyTrueConstraint. |
| packages/overture-schema-divisions-theme/src/overture/schema/divisions/division_boundary.py | Replaces @radio_group with @require_any_true. |
| packages/overture-schema-divisions-theme/src/overture/schema/divisions/division_area.py | Replaces @radio_group with @require_any_true. |
| packages/overture-schema-codegen/src/overture/schema/codegen/extraction/model_constraints.py | Adds description + field-affecting logic for the new constraint type. |
| packages/overture-schema-divisions-theme/tests/division_boundary_baseline_schema.json | Updates generated baseline schema to use anyOf. |
| packages/overture-schema-divisions-theme/tests/division_area_baseline_schema.json | Updates generated baseline schema to use anyOf. |
| examples/divisions/division_boundary/both_land_territorial.yaml | Makes the “both true” example valid (removes expected-error, adjusts fields). |
| examples/divisions/division_area/both_land_territorial.yaml | Adds a new valid “both true” example for division areas. |
| counterexamples/divisions/division_boundary/bad-not-both.yaml | Removes a counterexample that is now valid under anyOf. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com> Signed-off-by: Alex Iannicelli <atiannicelli@gmail.com>
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com> Signed-off-by: Alex Iannicelli <atiannicelli@gmail.com>
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> Signed-off-by: Alex Iannicelli <atiannicelli@gmail.com>
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> Signed-off-by: Alex Iannicelli <atiannicelli@gmail.com>
becab7a to
3df9e21
Compare
Victor Schappert (vcschapp)
left a comment
There was a problem hiding this comment.
Two comments:
- It might be useful to generalize
require_any_true. - The Python code doesn't use
examples/andcounterexamples/it usesreference/examples/andreference/counterexamples/- apologies for this inconsistency but could these be updated also?
| @@ -0,0 +1,151 @@ | |||
| """ | |||
There was a problem hiding this comment.
Can we generalize this slightly so that require_any_true takes a list of one or more Condition values? If that's workable then you could have, for this use case:
@require_any_true(FieldEqCondition('is_land', True), FieldEqCondition('is_territorial', True))
class DivisionArea(...):
...And for other use cases you can create more complex requirements this way, like "either field A should be set to 'foo' or field B should be set to 'bar'".
Summary
Replaces the
@radio_groupconstraint (exactly one must be true) with a new@require_any_trueconstraint (at least one must be true) onDivisionAreaandDivisionBoundarymodels. This allows bothis_landandis_territorialto betruesimultaneously.Changes
@require_any_trueconstraint inoverture-schema-system— validates that at least one field in a group ofboolfields isTrue, generatinganyOfin JSON Schema (vsoneOffrom@radio_group)DivisionAreaandDivisionBoundaryto use@require_any_true("is_land", "is_territorial")division_boundary.yaml) fromoneOf→anyOfbad-not-bothcounterexamples (now valid) and addedboth_land_territorialpositive examplesmodel_constraints.pyto handle the new constraint typeCloses #542