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

RecapType.is_nullable should iterate on union types #426

Merged
merged 1 commit into from
Feb 12, 2024

Conversation

criccomini
Copy link
Contributor

There was a bug in #423. Null types in a union with extra_attrs or other attributes set would result in False returned when there was in fact a NullType in the UnionType's types list. __eq__ checks all attributes, so you must iterate over the UnionType's types attribute and look for any type with isinstance(..., NullType) is True. I updated the logic accordingly.

In doing so, I discovered that the JSON converter logic was converting JSON schema fields of null type to a UnionType with a single nested NullType type. This seems wrong; I updated the test to validate that null JSON fields are returned as NullType with a default of None.

There was a bug in #423. Null types in a union with `extra_attrs` or other
attributes set would result in `False` returned when there was in fact a
NullType in the UnionType's `types` list. `__eq__` checks all attributes, so you
must iterate over the UnionType's `types` attribute and look for any type with
`isinstance(..., NullType) is True`. I updated the logic accordingly.

In doing so, I discovered that the JSON converter logic was converting JSON
schema fields of `null` type to a UnionType with a single nested NullType type.
This seems wrong; I updated the test to validate that `null` JSON fields are
returned as `NullType` with a default of `None`.
@criccomini
Copy link
Contributor Author

cc @adrianisk @mjperrone

Copy link
Contributor

@adrianisk adrianisk left a comment

Choose a reason for hiding this comment

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

Makes sense, thanks for wrapping this up!

@criccomini criccomini merged commit 00541ac into main Feb 12, 2024
3 checks passed
@criccomini criccomini deleted the json-nullable-tweaks branch February 12, 2024 22:45
@criccomini
Copy link
Contributor Author

criccomini commented Feb 29, 2024

Released in 0.12.0:

https://pypi.org/project/recap-core/0.12.0/

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.

None yet

2 participants