-
-
Notifications
You must be signed in to change notification settings - Fork 33.1k
gh-137899: Enhance shelve serializer validation with descriptive error messages #138768
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: main
Are you sure you want to change the base?
Conversation
self.deserializer = deserializer | ||
|
||
@staticmethod | ||
def _validate_serialized_value(serialized_value, original_value): |
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.
Validation is also at the level of the C extension (in dbmmodule.c) so you should also change the message out there.
else: | ||
invalid_type = type(serialized_value).__name__ | ||
msg = (f"Serializer returned {invalid_type} for value " | ||
f"{original_value!r} But database values must be " |
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.
Nitpick, 'But' should be lowercase unless it follows a period:
f"{original_value!r} But database values must be " | |
f"{original_value!r}, but database values must be " |
Adding a period before it is another option.
I've sent some suggestions as a PR to your branch: furkanonder#3 |
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 am not sure this is the best solution of the original issue. Making error messages in the underlying database more specific would help too.
msg = (f"Serializer returned {invalid_type} for value " | ||
f"{original_value!r} But database values must be " | ||
f"bytes or str, not {invalid_type}") |
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.
invalid_type
is repeated twice. This is unnecessary.
The repr of original_value
can be very large, it should not be included in the error message. Error most likely does not depend on the original value.
shelve
datum #137899