-
Notifications
You must be signed in to change notification settings - Fork 1.1k
PYTHON-1787: fix NotMasterError wrong attribute error #450
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
pymongo/errors.py
Outdated
@@ -114,7 +114,7 @@ class NotMasterError(AutoReconnect): | |||
Subclass of :exc:`~pymongo.errors.AutoReconnect`. | |||
""" | |||
def __str__(self): |
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.
As discussed earlier today, can you add a test that asserts that the "full error" string is included in str(exc) and traceback.format_exc()?
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.
Done.
test/test_monitoring.py
Outdated
@@ -439,6 +439,9 @@ def test_not_master_error(self): | |||
client.pymongo_test.test.find_one_and_delete({}) | |||
except NotMasterError as exc: | |||
error = exc.errors | |||
import traceback | |||
self.assertIn("full error", str(exc)) | |||
self.assertIn("full error", traceback.format_exc()) |
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.
This is exactly what I had in mind. What do you think about moving these assertions to their own test cases (maybe to a new file test_errors.py
)? You can use the error classes directly, like:
exc = NotMasterError(...)
self.assertIn("full error", str(exc))
try:
raise exc
except NotMasterError:
self.assertIn("full error", traceback.format_exc())
test/test_errors.py
Outdated
try: | ||
raise exc | ||
except NotMasterError: | ||
import traceback |
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.
Can you move this import to the top of the file?
test/test_errors.py
Outdated
|
||
class TestErrors(PyMongoTestCase): | ||
def test_not_master_error(self): | ||
exc = NotMasterError("not master test", "details") |
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.
Suggest using something like {ok: 0, errmsg:"error"}
instead of "details".
unittest) | ||
|
||
class TestErrors(PyMongoTestCase): | ||
def test_not_master_error(self): |
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.
Can you also add a similar test for OperationFailure?
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.
Done.
test/test_errors.py
Outdated
@@ -0,0 +1,18 @@ | |||
from pymongo.errors import (AutoReconnect, |
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.
Add the copyright notice # Copyright 2020-present MongoDB, Inc. ....
test/test_errors.py
Outdated
@@ -0,0 +1,18 @@ | |||
from pymongo.errors import (AutoReconnect, |
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.
After importing standard python libraries but before importing pymongo can you add sys.path[0:0] = [""]
. For example:
mongo-python-driver/test/test_bson.py
Line 27 in 4760d07
sys.path[0:0] = [""] |
raise exc | ||
except NotMasterError: | ||
import traceback | ||
self.assertIn("full error", traceback.format_exc()) |
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.
Can you add the if __name__ == "__main__":
logic at the bottom of this file?
mongo-python-driver/test/test_bson.py
Lines 1088 to 1089 in 4760d07
if __name__ == "__main__": | |
unittest.main() |
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.
Done.
client_knobs, | ||
PyMongoTestCase, | ||
sanitize_cmd, | ||
unittest) |
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.
Suggest removing any unused imports.
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.
Done.
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.
This is ready for review again
pymongo/errors.py
Outdated
@@ -114,7 +114,7 @@ class NotMasterError(AutoReconnect): | |||
Subclass of :exc:`~pymongo.errors.AutoReconnect`. | |||
""" | |||
def __str__(self): |
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.
Done.
client_knobs, | ||
PyMongoTestCase, | ||
sanitize_cmd, | ||
unittest) |
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.
Done.
unittest) | ||
|
||
class TestErrors(PyMongoTestCase): | ||
def test_not_master_error(self): |
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.
Done.
raise exc | ||
except NotMasterError: | ||
import traceback | ||
self.assertIn("full error", traceback.format_exc()) |
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.
Done.
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.
LGTM!
This is fixing the issue from the previous pull request which was caused by NotMasterError failing
https://jira.mongodb.org/browse/PYTHON-1787