ryncsn / metadash

A full stack boilerplate for building metadata manager and dashboard
Other
7 stars 4 forks source link

sqlalchemy 1.3 support #28

Open waynesun09 opened 5 years ago

waynesun09 commented 5 years ago

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'  
waynesun09 commented 5 years ago

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 commented 5 years ago

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.