Skip to content

fix: reject bound constraints that cannot be read as the field type - #1861

Open
mayuriphad wants to merge 1 commit into
frictionlessdata:mainfrom
mayuriphad:fix/invalid-bound-constraints
Open

mayuriphad wants to merge 1 commit into
frictionlessdata:mainfrom
mayuriphad:fix/invalid-bound-constraints

Conversation

@mayuriphad

Copy link
Copy Markdown

minimum, maximum, exclusiveMinimum and exclusiveMaximum are cast with the field's value reader in create_cell_reader. When the value can't be cast ("abc" or {} on an integer field, "not-a-date" on a date field), the reader returns None, the descriptor is accepted, and read_cell later fails with TypeError: '>' not supported between instances of 'int' and 'NoneType'.

Field.metadata_validate now reads each bound constraint with the same value reader and yields a FieldError when the result is None:

constraint "exclusiveMinimum" value "abc" is not a valid "integer"

The reader comes from a field built from the descriptor itself (minus constraints and example), so field options such as format, decimalChar or groupChar apply in the same way as when reading cells. For example, a date field with format: "%d/%m/%Y" and minimum: "01/02/2020" is still accepted. Only constraints the type supports are checked; unsupported ones keep their existing error.

Tests in frictionless/schema/__spec__/field/test_constraints.py:

  • test_field_bound_constraint_invalid_value: each of the four constraints with an uncastable value on integer, number, date, datetime, time, year and yearmonth fields. The 32 cases fail on main and pass with this change.
  • test_field_bound_constraint_value_read_with_field_options: a custom date format bound is accepted and still applied.

The existing valid-constraint table in the same file still passes. I also ran the schema, fields, resource, package, metadata, validator, steps, table and detector specs with and without the change: the set of failures is identical (they come from optional plugins and network access missing in my environment). ruff check and ruff format (ruff < 0.16, as pinned) are clean.

minimum, maximum, exclusiveMinimum and exclusiveMaximum are cast with the
field's value reader when cells are read. A value that cannot be cast
(e.g. "abc" on an integer field) became None, the descriptor was
accepted, and read_cell then raised a raw TypeError from the comparison.

Validate these constraints in Field.metadata_validate with the same value
reader, built from the field's own options so formats and number
separators are honoured, and report a FieldError.

Fixes frictionlessdata#1841

Signed-off-by: mayuriphad <mayuriphad656@gmail.com>
Copilot AI balanced review requested due to automatic review settings October 18, 2026 18:21

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.

@mayuriphad

Copy link
Copy Markdown
Author

Hi, just a gentle ping on this PR. It's ready for review whenever you have time, and I'm happy to make any changes you'd like. Thanks!

This branch has not been deployed

No deployments
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: invalid constraints in descriptor do not raise a FieldError

2 participants