Repository navigation
fix: reject bound constraints that cannot be read as the field type - #1861
Open
mayuriphad wants to merge 1 commit into
Open
mayuriphad wants to merge 1 commit into
mayuriphad wants to merge 1 commit into
Conversation
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>
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
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.
minimum,maximum,exclusiveMinimumandexclusiveMaximumare cast with the field's value reader increate_cell_reader. When the value can't be cast ("abc"or{}on an integer field,"not-a-date"on a date field), the reader returnsNone, the descriptor is accepted, andread_celllater fails withTypeError: '>' not supported between instances of 'int' and 'NoneType'.Field.metadata_validatenow reads each bound constraint with the same value reader and yields aFieldErrorwhen the result isNone:The reader comes from a field built from the descriptor itself (minus
constraintsandexample), so field options such asformat,decimalCharorgroupCharapply in the same way as when reading cells. For example, a date field withformat: "%d/%m/%Y"andminimum: "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 onmainand 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,tableanddetectorspecs with and without the change: the set of failures is identical (they come from optional plugins and network access missing in my environment).ruff checkandruff format(ruff < 0.16, as pinned) are clean.