-
Notifications
You must be signed in to change notification settings - Fork 90
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
Remove potentially-buggy positive_id #384
Merged
Merged
Conversation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
positive_id was added in 2004 in f7b96ae (ZODB.utils grows a new function positive_id(), which returns the id() of an object as a non-negative integer ...) to workaround change in behaviour Python2.3 -> 2.4 for `'%x' % <negative-number>`. And nowdays `positive_id` is used only in one place in Connection.__repr__ to mimic approximately what Python already gives for a default __repr__ out of the box. On https://github.com/zopefoundation/ZODB/actions/runs/5067242751/jobs/9098062772 we recently hit ZODB.POSException.InvalidObjectReference: <unprintable InvalidObjectReference object> for the following code: if self._jar.get_connection(database_name) is not obj._p_jar: raise InvalidObjectReference( "Attempt to store a reference to an object from " "a separate connection to the same database or " "multidatabase", self._jar, obj, ) ( https://github.com/zopefoundation/ZODB/blob/5.8.0-24-g8a7e3162d/src/ZODB/serialize.py#L366-L371 ) for which the "unprintable ..." part is produced by `Lib/traceback.py` who tries to do `str(ex)` and returns `unprintable ...` if that str failed: https://github.com/python/cpython/blob/v3.8.16-18-g9f89c471fb1/Lib/traceback.py#L153-L157 Since one of the reasons for that failure might have been a bit non-trivial code and assert in positive_id, let's remove it and rely on builtin python behaviour for Connection repr. repr for Connection: before this patch: <Connection at 0x7fef09989d10> after this patch: <ZODB.Connection.Connection object at 0x7fef09989d10>
dataflake
approved these changes
May 26, 2023
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.
Any change that removes homegrown replacements for built-in functionality is a win.
Thanks, Jens. |
Dieter, are you ok with this patch? |
d-maurer
approved these changes
May 26, 2023
Thanks, Dieter. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
positive_id was added in 2004 in f7b96ae (ZODB.utils grows a new function positive_id(), which returns the id() of an object as a non-negative integer ...) to workaround change in behaviour Python2.3 -> 2.4 for
'%x' % <negative-number>
. And nowdayspositive_id
is used only in one place in Connection.repr to mimic approximately what Python already gives for a default repr out of the box.On https://github.com/zopefoundation/ZODB/actions/runs/5067242751/jobs/9098062772 we recently hit
for the following code:
( https://github.com/zopefoundation/ZODB/blob/5.8.0-24-g8a7e3162d/src/ZODB/serialize.py#L366-L371 )
for which the "unprintable ..." part is produced by
Lib/traceback.py
who tries to dostr(ex)
and returnsunprintable ...
if that str failed:https://github.com/python/cpython/blob/v3.8.16-18-g9f89c471fb1/Lib/traceback.py#L153-L157
Since one of the reasons for that failure might have been a bit non-trivial code and assert in positive_id, let's remove it and rely on builtin python behaviour for Connection repr.
repr for Connection:
before this patch:
after this patch: