Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix parsing BigInt from str #1204

Merged
merged 2 commits into from
Mar 5, 2024
Merged

Fix parsing BigInt from str #1204

merged 2 commits into from
Mar 5, 2024

Conversation

sydney-runkle
Copy link
Member

@sydney-runkle sydney-runkle commented Feb 23, 2024

FIx pydantic/pydantic#8835

Selected Reviewer: @davidhewitt

Copy link

codspeed-hq bot commented Feb 23, 2024

CodSpeed Performance Report

Merging #1204 will not alter performance

Comparing fix_big_int_issues (e2c0184) with main (47aff70)

Summary

✅ 148 untouched benchmarks

@sydney-runkle
Copy link
Member Author

Please review

Copy link
Member

@samuelcolvin samuelcolvin left a comment

Choose a reason for hiding this comment

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

in general looks good, I think it could do with a couple more tests, and checking the strct vs. lax thing.

Ok(i) => Ok(ValidationMatch::strict(EitherInt::I64(i))),
Err(_) => Err(ValError::new(ErrorTypeDefaults::IntParsing, self)),
},
Self::String(s) => str_as_int(self, py_string_str(s)?).map(ValidationMatch::strict),
Copy link
Member

Choose a reason for hiding this comment

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

who is one ValidationMatch::strict and one ValidationMatch::lax?

Copy link
Member

Choose a reason for hiding this comment

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

maybe add a test for both cases.

Copy link
Member Author

Choose a reason for hiding this comment

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

Not sure, though I just kept the logic consistent with what was there before...

Copy link
Contributor

Choose a reason for hiding this comment

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

This will control union behaviour, to add test cases would need to put these in unions with str as the equivalent validator on the RHS, and confirm that in both cases the str leg wins?

e.g. dict[int, str] | dict[str, str] - I guess the dict[str, str] is the better choice.

Copy link
Contributor

Choose a reason for hiding this comment

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

As discussed with @sydney-runkle offline, I think the divergence is a historical bug that's probably on me. Let's not block this PR on it.

big_integer = 1433352099889938534014333520998899385340
assert v.validate_python({big_integer: 'x'}) == {big_integer: 'x'}
assert v.validate_json('{"' + str(big_integer) + '": "x"}') == {big_integer: 'x'}
assert v.validate_strings({str(big_integer): 'x'}) == {big_integer: 'x'}
Copy link
Member

Choose a reason for hiding this comment

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

definitely worth adding a test for valdiate_string.

Copy link
Member Author

Choose a reason for hiding this comment

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

@samuelcolvin,

Did you have something different in mind than the line above?

assert v.validate_strings({str(big_integer): 'x'}) == {big_integer: 'x'}

@sydney-runkle sydney-runkle merged commit c6301fe into main Mar 5, 2024
27 checks passed
@sydney-runkle sydney-runkle deleted the fix_big_int_issues branch March 5, 2024 17:56
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Fails to parse large integers from json when they are dict keys
3 participants