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 is not properly initialized when created by a declared_attr of a mixin class #4185
Comments
Changes by Eric Atkin (Omni):
|
1 similar comment
Changes by Eric Atkin (Omni):
|
Michael Bayer (@zzzeek) wrote: that commit was cherry-picked to 1.1. but no issue in 1.1? |
Michael Bayer (@zzzeek) wrote: also:
|
Michael Bayer (@zzzeek) wrote: oh, the return value is what's not right. OK, test cases shoudl really give me a stack trace, that's much more helpful |
Michael Bayer (@zzzeek) wrote: and it occurs in 1.1 as well. because the code is the same. mysteries continue |
Eric Atkin (Omni) wrote: Updated test case to actually trigger an exception |
Changes by Eric Atkin (Omni):
|
Eric Atkin (Omni) wrote: Something is wrong with bitbucket. I've been trying to respond to each of your questions, but when I submit a comment, I just get an infinite spinner. I can edit the issue description apparently. So re: 1.1, I upgraded from 1.1.14 where I didn't have the issue. I assume you cherry-picked it into 1.1.15 where we both see the problem in addition to 1.2. |
Changes by Eric Atkin (Omni):
|
Michael Bayer (@zzzeek) wrote: great that makes sense thanks |
Michael Bayer (@zzzeek) wrote: your situation was a little more unlikely than you might assume but nonetheless this was pretty broken, in https://gerrit.sqlalchemy.org/#/q/I611b590df2babe077ce6c19bea89e84251d1a7f4 i hopefully have the last time I have to keep fixing this |
Eric Atkin (Omni) wrote: I'm sure my model design was very unlikely, but a perfect storm for this |
Michael Bayer (@zzzeek) wrote: Search through mapper superclass hierarchy for owner Fixed regression caused by fix for issue 🎫 Change-Id: I611b590df2babe077ce6c19bea89e84251d1a7f4 → 650b9ed |
Changes by Michael Bayer (@zzzeek):
|
Michael Bayer (@zzzeek) wrote: Search through mapper superclass hierarchy for owner Fixed regression caused by fix for issue 🎫 Change-Id: I611b590df2babe077ce6c19bea89e84251d1a7f4 → cc6cef5 |
Robbe Block (@robbeblock) wrote: Hey guys, Unfortunately, after upgrading to 1.2.3 from 1.2.2, our models now break and I think it might be related to this fix. I've added the relevant part of the stack trace below, but basically it boils down to SQLAlchemy being unable to detect the owner (which lead me to think it has to do something with these changes)
I don't have a fully distilled example of how to reproduce it for now, but in broad strokes it comes down to having 2 models, File and Resource and 2 relationships between these two models. We created the double relationship by creating intermediate models: ExternalFiles and InternalFiles. The models are declared in order and the relationships are defined on ExternalFiles and InternalFiles (so that they can refer to the already existing models instead of using a string reference to their name). However, the association proxies are defined on Resource as
Could it have to do with the fact that I'm declaring the proxy before the actual relationship is declared? |
Michael Bayer (@zzzeek) wrote: not sure but I really rewrote that stuff, so not surprised it broke yet again |
Changes by Michael Bayer (@zzzeek):
|
Michael Bayer (@zzzeek) wrote: @robbeblock I really need the complete stack trace to know how you are accessing this association proxy (class level, instance level, mappers configured yet or not, etc) |
Michael Bayer (@zzzeek) wrote: @robbeblock I can imagine that your mappings use mixins or something like that? I can reproduce your error but not quite with the segment of mappings you're showing. |
Michael Bayer (@zzzeek) wrote: OK, the condition you describe is revised in https://gerrit.sqlalchemy.org/#/q/I87d0ac09f695dc285bd4bbe0a547f1d5ce23e068 which will go in and be released very soon, it likely fixes your issue as well though I'd still like to see specifically how you are getting that error. |
Robbe Block (@robbeblock) wrote: I'm afraid the stack trace on its own won't do you much good, but I added it below anyway.
The error pops up as soon as I try to print the proxied value (as in I indeed use mixins in my mappings abstracted away by some home-grown decorators (which seemed like a good idea at the time, but now it seems that it complicates things too much especially when trying to extract the pure SQLAlchemy models). If it is not resolved by your proposed fix, I'll try my best to squeeze out some time to provide you with a decent example. In the mean time, what I do is declare all my models with their 'normal' properties (as in: all non-relationships properties) in regular Python classes, then add in relationships between the models using the custom made decorators and later then mix in the resulting model with flask-sqlalchemy's db.Model - looking at SQLAlchemy's code, this boils down to a class being fed to Anyway, already many thanks to the speedy response! |
Michael Bayer (@zzzeek) wrote: so already that tells me a lot, e.g. you have the instance, not the class, that you are accessing the attribute from. next, this "external_files" association proxy -where it is present in your source code, is the immediate parent class a mixin and not a mapped class? that is:
that would be the other side of it. can you try the patch at https://gerrit.sqlalchemy.org/#/c/zzzeek/sqlalchemy/+/673/ (you can download https://gerrit.sqlalchemy.org/changes/673/revisions/93881f7873048403b62cc3e179354712ba8e9282/patch?zip as one option) . then we'll know this fixes it for you. i can maybe release today or tomorrow. |
Robbe Block (@robbeblock) wrote: Yes, the immediate parent class of the association proxy is a mixin and not mapped at the moment of declaration. I'll get back to you as soon as I tried the patch. |
Robbe Block (@robbeblock) wrote: I just checked the patch and is seems to work. Nice job! |
Michael Bayer (@zzzeek) wrote: Default to using current mapped class as owner if none found Repaired regression caused in 1.2.3 and 1.1.16 regarding association proxy Change-Id: I87d0ac09f695dc285bd4bbe0a547f1d5ce23e068 → 66a246b |
Michael Bayer (@zzzeek) wrote: Default to using current mapped class as owner if none found Repaired regression caused in 1.2.3 and 1.1.16 regarding association proxy Change-Id: I87d0ac09f695dc285bd4bbe0a547f1d5ce23e068 → b37f007 |
Changes by Michael Bayer (@zzzeek):
|
Migrated issue, originally created by Eric Atkin (Omni)
After upgrading from 1.1.14 to 1.2.2, my models broke (later testing shows the error in 1.1.15 as well). A simplified representation is included below that demonstrates the issue. If the Parent.children association proxy is not accessed before any subclasses are defined, it's owning_class attribute will be None.
This seems to be caused by the fix for issue #4116 in commit f14a58d
I don't know how to fix this, but am able to work around it for now by accessing the proxy attribute prior to the subclass definitions. I hope that by demonstrating it, you would be able to design a change that addresses the original issue and mitigates this side-effect.
Thank you,
Eric
The text was updated successfully, but these errors were encountered: