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
AssociationProxy becomes useless when parent goes out of scope #4268
Comments
Michael Bayer (@zzzeek) wrote: As I'm sure you can see, the design here is not by accident. However, it is an extremely old use case which I've not tested recently. After extensive searching I've located the origin of the weakref is in 84420a1 and it does seem to include modifications to tests, however I can confirm adding a strong ref does not fail current tests. The original issue is #597. The issue described in #597 is not reproducible if I include a simple strong ref inside of _lazy_collection. A suite of tests that is guaranteed to fail differently whether or not there is a strong ref can be added as follows, illustrating where the inconsistency can go. Since the "dynamic" collection is also holding onto the parent object that sets precedent to revert the weak reference. if it fails in the wild then we'll get a nice new test case however it may mean we'd have to revert the change again:
|
Michael Bayer (@zzzeek) wrote:
you might be surprised how upset people get when we add reference cycles to their objects. although in modern uses I'm not sure we are fully preventing against cycles in all cases now. |
Michael Bayer (@zzzeek) wrote: |
Changes by Michael Bayer (@zzzeek):
|
Michael Bayer (@zzzeek) wrote: Strong reference parent object in association proxy Considering the reversal of #597 as well as The long-standing behavior of the association proxy collection maintaining Change-Id: I051334be90a343dd0e8a1f35e072075eb14b14a7 → 11947c3 |
Changes by Michael Bayer (@zzzeek):
|
Michael Bayer (@zzzeek) wrote: so keep in mind, I'm expecting people might complain about this. But since I have no recent data on that, and the original issue doesn't reproduce, I'm actually merging it into 1.3 just so we can collect more data on this, it might have to be something that is configurable. Hopefully if people have a problem with it, it can be worked out within the 1.3 betas. |
Migrated issue, originally created by Chris Wilson (@qris1)
This fails:
Because User is garbage-collected before the association can be read:
Whereas if you forcibly keep a reference in a variable, then it works:
Other people have run into this issue as well:
The latter has some explanation as to why we only keep a weakref:
Preventing reference cycles doesn't seem like a good reason to have such counter-intuitive behaviour. Also we may not need to hold a strong reference to the underlying association. A strong reference to the parent of that association should be enough to prevent it from going out of scope, keeping the association object accessible/constructable.
The text was updated successfully, but these errors were encountered: