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
How to handle ConnectionStateErrors when looking up for adapters and closed connections #271
Comments
CCing @jamadden because he worked on zopefoundation/zope.component#53 |
Alessandro Pisa wrote at 2023-6-8 03:04 -0700:
When we look up for adapters:
https://github.com/zopefoundation/zope.interface/blob/405017fef489ff9d517d0e86e6cb0e6a14fb9bd6/src/zope/interface/adapter.py#L818
We might have:
1. a closed connection
2. and a persistent adapter registry
When you access a persistent object with a closed connection,
you do something fundamentally wrong:
the object might be a ghost and then it cannot be loaded when the connection
is not open.
You therefore must **never** store a persistent object at module or class
level (e.g. in a cache).
Any activity (e.g. thread) can access a persistent object only
either directly via the connection (e.g. the ZODB root) or
indirectly via object attributes of a persistent object it has itself
accessed. In those cases, the connection is not closed.
|
I agree that this is not good. |
Alessandro Pisa wrote at 2023-6-8 08:18 -0700:
I agree that this is not good.
Probably that `PersistentList` does not even have what I am looking for :)
But they point is that with the previous implementation (which used a `list` instead of a `PersistentList`) it was working.
Bad access to a persistent object is not detected reliably --
only when the object happens to be a ghost.
I am quite sure that the problem you now observe has been there already
- but has not been detected:
when the connection of a persistent object is closed, the parent's connection
(in almost all cases, it is the same connection) is likely closed, too.
However, while the object might be a ghost (leading to the detection
of the closed connection), the parent might not be a ghost (and the
closed connection is not detected).
|
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
When we look up for adapters:
zope.interface/src/zope/interface/adapter.py
Line 818 in 405017f
We might have:
See:
This causes the
_uncached_subscriptions
to raise aConnectionStateError
.The issue happens since
zope.component
5, before the persistent adapter registry was storing alist
, see:What would be the best way to handle this issue?
Adding a:
might be an idea?
Originally discovered while debugging:
plone/plone.testing#83
What version of Python and Zope/Addons I am using:
Tested on Plone 6 with:
The text was updated successfully, but these errors were encountered: