-
Notifications
You must be signed in to change notification settings - Fork 1.1k
PYTHON-2354 Add support for JSONOptions.with_options #482
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
PYTHON-2354 Add support for JSONOptions.with_options #482
Conversation
bson/json_util.py
Outdated
'datetime_representation', self.datetime_representation), | ||
strict_uuid=kwargs.pop('strict_uuid', self.strict_uuid), | ||
json_mode=kwargs.pop('json_mode', self.json_mode), | ||
**kwargs) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we need to copy all the JSONOptions and CodecOptions attributes here otherwise some settings will be lost.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good point. I made this change and also added a test case that fails if this is not true.
Can you open a ticket for the SRV test failures?
|
bson/json_util.py
Outdated
'uuid_representation', | ||
'unicode_decode_error_handler', | ||
'tzinfo', | ||
'type_registry') |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It might be more future proof to use self._fields
to get all the fields from CodecOptions. https://docs.python.org/3/library/collections.html#collections.somenamedtuple._fields
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I used _as_dict()
instead as it seemed more tailored to our usecase.
Opened https://jira.mongodb.org/browse/PYTHON-2362 for SRV failures. |
) | ||
opts = self._asdict() | ||
opts.update(kwargs) | ||
return CodecOptions(**opts) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice!
Open question: Should we throw an exception if the user tries to change the
JSONMode
viawith_options
?