-
Notifications
You must be signed in to change notification settings - Fork 1.1k
PYTHON-5449 - Do not attach invalid document in exception message #2539
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
base: master
Are you sure you want to change the base?
Changes from 4 commits
296372e
cc07a59
4fb872e
ca9f09f
2319a43
6c73d1e
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -1645,7 +1645,7 @@ static int write_raw_doc(buffer_t buffer, PyObject* raw, PyObject* _raw_str) { | |
} | ||
|
||
|
||
/* Update Invalid Document error message to include doc. | ||
/* Update Invalid Document error to include doc as a property. | ||
*/ | ||
void handle_invalid_doc_error(PyObject* dict) { | ||
PyObject *etype = NULL, *evalue = NULL, *etrace = NULL; | ||
|
@@ -1659,20 +1659,13 @@ void handle_invalid_doc_error(PyObject* dict) { | |
if (evalue && PyErr_GivenExceptionMatches(etype, InvalidDocument)) { | ||
PyObject *msg = PyObject_Str(evalue); | ||
if (msg) { | ||
// Prepend doc to the existing message | ||
PyObject *dict_str = PyObject_Str(dict); | ||
if (dict_str == NULL) { | ||
goto cleanup; | ||
} | ||
const char * dict_str_utf8 = PyUnicode_AsUTF8(dict_str); | ||
if (dict_str_utf8 == NULL) { | ||
goto cleanup; | ||
} | ||
// Add doc to the error class as a property. | ||
PyObject_SetAttrString(InvalidDocument, "document", dict); | ||
|
||
const char * msg_utf8 = PyUnicode_AsUTF8(msg); | ||
if (msg_utf8 == NULL) { | ||
goto cleanup; | ||
} | ||
PyObject *new_msg = PyUnicode_FromFormat("Invalid document %s | %s", dict_str_utf8, msg_utf8); | ||
PyObject *new_msg = PyUnicode_FromFormat("Invalid document: %s", msg_utf8); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. For an invalid field in a nested doc, does this yield errors like "Invalid document: Invalid document: Invalid document: Invalid document: Invalid document: ...."? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. No, it works as expected:
|
||
Py_DECREF(evalue); | ||
Py_DECREF(etype); | ||
etype = InvalidDocument; | ||
|
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.
Shouldn't this InvalidDocument except clause include the encoding of
_id
too?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.
That would be a pre-existing bug, no? Happy to fix if we identify why the code currently looks like this. Maybe we assume that
_id
will be valid if it reaches this far?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.
Correct it would be a pre-existing bug. Could you open a ticket for it?
vs the expected behavior:
Uh oh!
There was an error while loading. Please reload this page.
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.
Opened PYTHON-5560 to track.