diff options
| author | mike bayer <mike_mp@zzzcomputing.com> | 2019-03-27 17:38:02 +0000 |
|---|---|---|
| committer | Gerrit Code Review <gerrit@bbpush.zzzcomputing.com> | 2019-03-27 17:38:02 +0000 |
| commit | 9168aae5e7cc9a753acf7e132c89e35eb56bb4ea (patch) | |
| tree | a95658d69a0ad9a9ef977df57f684f7ff77b5750 /lib | |
| parent | 1f6871ef0e954813b438bb65f10f58a4a31d0c42 (diff) | |
| parent | 51f81d00dc6103c1dea939513a3437a5ab433e75 (diff) | |
| download | sqlalchemy-9168aae5e7cc9a753acf7e132c89e35eb56bb4ea.tar.gz | |
Merge "Refine ambiguous access for unknown attribute types"
Diffstat (limited to 'lib')
| -rw-r--r-- | lib/sqlalchemy/ext/associationproxy.py | 23 |
1 files changed, 21 insertions, 2 deletions
diff --git a/lib/sqlalchemy/ext/associationproxy.py b/lib/sqlalchemy/ext/associationproxy.py index ea3b8fade..b8672e739 100644 --- a/lib/sqlalchemy/ext/associationproxy.py +++ b/lib/sqlalchemy/ext/associationproxy.py @@ -295,6 +295,12 @@ class AssociationProxy(interfaces.InspectionAttrInfo): return getter, setter + def __repr__(self): + return "AssociationProxy(%r, %r)" % ( + self.target_collection, + self.value_attr, + ) + class AssociationProxyInstance(object): """A per-class object that serves class- and object-specific results. @@ -385,7 +391,11 @@ class AssociationProxyInstance(object): ) attr = getattr(target_class, value_attr) - if attr._is_internal_proxy and not hasattr(attr, "impl"): + if ( + not hasattr(attr, "_is_internal_proxy") + or attr._is_internal_proxy + and not hasattr(attr, "impl") + ): return AmbiguousAssociationProxyInstance( parent, owning_class, target_class, value_attr ) @@ -724,6 +734,9 @@ class AssociationProxyInstance(object): criterion=criterion, is_has=True, **kwargs ) + def __repr__(self): + return "%s(%r)" % (self.__class__.__name__, self.parent) + class AmbiguousAssociationProxyInstance(AssociationProxyInstance): """an :class:`.AssociationProxyInstance` where we cannot determine @@ -748,10 +761,16 @@ class AmbiguousAssociationProxyInstance(AssociationProxyInstance): def get(self, obj): if obj is None: - self._ambiguous() + return self else: return super(AmbiguousAssociationProxyInstance, self).get(obj) + def __eq__(self, obj): + self._ambiguous() + + def __ne__(self, obj): + self._ambiguous() + def any(self, criterion=None, **kwargs): self._ambiguous() |
