Skip to content
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

sqlalchemy 1.3 support #28

Open
waynesun09 opened this issue Mar 6, 2019 · 2 comments
Open

sqlalchemy 1.3 support #28

waynesun09 opened this issue Mar 6, 2019 · 2 comments
Assignees

Comments

@waynesun09
Copy link
Contributor

waynesun09 commented Mar 6, 2019

SQLAlchemy have new 1.3 release:

https://docs.sqlalchemy.org/en/latest/changelog/migration_13.html#change-2642

AssociationProxy now support 'like', also contains function have updated, also Implemented bulk replace for sets, dicts with AssociationProxy.

With testing we hit on a bug with:

  File "/home/wayne/.local/share/virtualenvs/metadash-M-x0RP1C/lib/python3.6/site-packages/sqlalchemy/ext/associationp
roxy.py", line 960, in __setstate__                                                                                   
    self.parent._inflate(self)                                                                                        
AttributeError: 'AssociationProxy' object has no attribute '_inflate'  
@ryncsn ryncsn self-assigned this Mar 6, 2019
@waynesun09
Copy link
Contributor Author

To fix from sqlalchemy side could be:

--- a/lib/sqlalchemy/ext/associationproxy.py
+++ b/lib/sqlalchemy/ext/associationproxy.py
@@ -956,7 +956,11 @@ class _AssociationCollection(object):
     def __setstate__(self, state):
         self.parent = state["parent"]
         self.lazy_collection = state["lazy_collection"]
-        self.parent._inflate(self)
+        if isinstance(self.parent, AssociationProxy):
+            self.parent.for_class(self.parent.owning_class)._inflate(self)
+        else:
+            self.parent._inflate(self)

To contribute, test is required with the fix which is hard to add.

@yukinchan
Copy link
Contributor

I've done some research and believe that it is a bug in sqlachemy. What _inflate() does is to set the proper creator, setter and getter for a association_proxy from its parent. But since association_proxy no longer stores its parent[1], this would be definitely a runtime error.

[1]:New in version 1.3: - AssociationProxy no longer stores any state specific to a particular parent class; the state is now stored in per-class AssociationProxyInstance objects.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants