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

Variant requires Dict to have both key and value. #62

Merged
merged 1 commit into from May 8, 2021
Merged

Conversation

jamadden
Copy link
Member

@jamadden jamadden commented May 6, 2021

Raise an error at construction time instead of waiting until when the field is validating.

Fixes #59

Raise an error at construction time instead of waiting until when the field is validating.

Fixes #59
@jamadden jamadden requested a review from cutz May 6, 2021 21:20
@cutz
Copy link

cutz commented May 7, 2021

This looks reasonable to me. I did a quick audit looking for where we may see errors. There's the location that led to me opening the linked issue. How about something like Variant((Object(IDict)) is that going to require we add a key_type and value_type or other wise convert Object(IDict) to something else?

https://github.com/NextThought/nti.dataserver/blob/c2dbc10a922e4ebc62cfc08a29ead6ddb4a60ced/src/nti/contentsearch/interfaces.py#L163

@jamadden
Copy link
Member Author

jamadden commented May 7, 2021

How about something like Variant((Object(IDict))

If it's caught by this test/change, it definitely wouldn't have worked before — it would have been raising AttributeError. If it's not caught by this test, it may or may not have worked, and it still may or may not. Either way, I don't see a compatibility issue.

Does that check out?

ETA: Yeah, it works:

>>> from nti.schema.field import Object
>>> from nti.schema.field import Variant
>>> from zope.interface.common.collections import IMapping
>>>
>>> v = Variant([Object(IMapping)])
>>> v.fromObject({'a': 'b'})
{'a': 'b'}

@jamadden jamadden merged commit 7325a98 into master May 8, 2021
@jamadden jamadden deleted the issue59 branch May 8, 2021 11:14
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.

Poor handling of Dict objects missing a key/value type inside a Variant -> AttributeError
2 participants