Open waynesun09 opened 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.
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.
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: