Skip to content

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

Conversation

prashantmital
Copy link
Contributor

@prashantmital prashantmital commented Sep 8, 2020

Open question: Should we throw an exception if the user tries to change the JSONMode via with_options?

'datetime_representation', self.datetime_representation),
strict_uuid=kwargs.pop('strict_uuid', self.strict_uuid),
json_mode=kwargs.pop('json_mode', self.json_mode),
**kwargs)
Copy link
Member

@ShaneHarvey ShaneHarvey Sep 8, 2020

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.

Copy link
Contributor Author

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.

@ShaneHarvey
Copy link
Member

Can you open a ticket for the SRV test failures?

 [2020/09/09 00:30:19.743] ERROR [21.125s]: test_addition (test_srv_polling.TestSrvPolling)
 [2020/09/09 00:30:19.743] ----------------------------------------------------------------------
 [2020/09/09 00:30:19.743] Traceback (most recent call last):
 [2020/09/09 00:30:19.743]   File "/data/mci/7519f65052e35304de9578b97269a64e/src/pymongo/srv_resolver.py", line 72, in _resolve_uri
 [2020/09/09 00:30:19.743]     results = resolver.query('_mongodb._tcp.' + self.__fqdn, 'SRV',
 [2020/09/09 00:30:19.743]   File "/data/mci/7519f65052e35304de9578b97269a64e/src/test/utils.py", line 307, in __call__
 [2020/09/09 00:30:19.743]     return self._function(*args, **kwargs)
 [2020/09/09 00:30:19.743]   File "/opt/python/3.8/lib/python3.8/site-packages/dns/resolver.py", line 1221, in query
 [2020/09/09 00:30:19.743]     return resolve(qname, rdtype, rdclass, tcp, source,
 [2020/09/09 00:30:19.743]   File "/opt/python/3.8/lib/python3.8/site-packages/dns/resolver.py", line 1205, in resolve
 [2020/09/09 00:30:19.743]     return get_default_resolver().resolve(qname, rdtype, rdclass, tcp, source,
 [2020/09/09 00:30:19.743]   File "/opt/python/3.8/lib/python3.8/site-packages/dns/resolver.py", line 1043, in resolve
 [2020/09/09 00:30:19.743]     timeout = self._compute_timeout(start, lifetime)
 [2020/09/09 00:30:19.743]   File "/opt/python/3.8/lib/python3.8/site-packages/dns/resolver.py", line 950, in _compute_timeout
 [2020/09/09 00:30:19.743]     raise Timeout(timeout=duration)
 [2020/09/09 00:30:19.743] dns.exception.Timeout: The DNS operation timed out after 21.122992515563965 seconds
 [2020/09/09 00:30:19.743] During handling of the above exception, another exception occurred:
 [2020/09/09 00:30:19.743] Traceback (most recent call last):
 [2020/09/09 00:30:19.743]   File "/data/mci/7519f65052e35304de9578b97269a64e/src/test/test_srv_polling.py", line 165, in test_addition
 [2020/09/09 00:30:19.743]     self.run_scenario(response, True)
 [2020/09/09 00:30:19.743]   File "/data/mci/7519f65052e35304de9578b97269a64e/src/test/test_srv_polling.py", line 153, in run_scenario
 [2020/09/09 00:30:19.743]     client = MongoClient(self.CONNECTION_STRING)
 [2020/09/09 00:30:19.743]   File "/data/mci/7519f65052e35304de9578b97269a64e/src/pymongo/mongo_client.py", line 639, in __init__
 [2020/09/09 00:30:19.743]     res = uri_parser.parse_uri(
 [2020/09/09 00:30:19.743]   File "/data/mci/7519f65052e35304de9578b97269a64e/src/pymongo/uri_parser.py", line 500, in parse_uri
 [2020/09/09 00:30:19.743]     nodes = dns_resolver.get_hosts()
 [2020/09/09 00:30:19.743]   File "/data/mci/7519f65052e35304de9578b97269a64e/src/pymongo/srv_resolver.py", line 102, in get_hosts
 [2020/09/09 00:30:19.743]     _, nodes = self._get_srv_response_and_hosts(True)
 [2020/09/09 00:30:19.743]   File "/data/mci/7519f65052e35304de9578b97269a64e/src/pymongo/srv_resolver.py", line 83, in _get_srv_response_and_hosts
 [2020/09/09 00:30:19.743]     results = self._resolve_uri(encapsulate_errors)
 [2020/09/09 00:30:19.743]   File "/data/mci/7519f65052e35304de9578b97269a64e/src/pymongo/srv_resolver.py", line 79, in _resolve_uri
 [2020/09/09 00:30:19.743]     raise ConfigurationError(str(exc))
 [2020/09/09 00:30:19.743] pymongo.errors.ConfigurationError: The DNS operation timed out after 21.122992515563965 seconds

'uuid_representation',
'unicode_decode_error_handler',
'tzinfo',
'type_registry')
Copy link
Member

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

Copy link
Contributor Author

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.

@prashantmital
Copy link
Contributor Author

Opened https://jira.mongodb.org/browse/PYTHON-2362 for SRV failures.

)
opts = self._asdict()
opts.update(kwargs)
return CodecOptions(**opts)
Copy link
Member

Choose a reason for hiding this comment

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

Nice!

@prashantmital prashantmital merged commit 963759a into mongodb:master Sep 9, 2020
@prashantmital prashantmital deleted the PYTHON-2354/JSONOptions.with_option-support branch September 9, 2020 21:15
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.

2 participants