diff options
author | Mike Bayer <mike_mp@zzzcomputing.com> | 2014-02-27 13:29:59 -0500 |
---|---|---|
committer | Mike Bayer <mike_mp@zzzcomputing.com> | 2014-02-27 13:29:59 -0500 |
commit | b6428219c663e0eb0bf44817391d7a8fc1c60d43 (patch) | |
tree | e7b233e5ba80ba199035299e472f754393d350b9 /lib/sqlalchemy | |
parent | 2d146ddad97e637c399d274c845866d2e21e9b93 (diff) | |
download | sqlalchemy-b6428219c663e0eb0bf44817391d7a8fc1c60d43.tar.gz |
- Fixed a regression in association proxy caused by :ticket:`2810` which
caused a user-provided "getter" to no longer receive values of ``None``
when fetching scalar values from a target that is non-present. The
check for None introduced by this change is now moved into the default
getter, so a user-provided getter will also again receive values of
None.
re: #2810
Diffstat (limited to 'lib/sqlalchemy')
-rw-r--r-- | lib/sqlalchemy/ext/associationproxy.py | 8 |
1 files changed, 3 insertions, 5 deletions
diff --git a/lib/sqlalchemy/ext/associationproxy.py b/lib/sqlalchemy/ext/associationproxy.py index e62958b49..a4786de42 100644 --- a/lib/sqlalchemy/ext/associationproxy.py +++ b/lib/sqlalchemy/ext/associationproxy.py @@ -243,10 +243,7 @@ class AssociationProxy(interfaces._InspectionAttr): if self.scalar: target = getattr(obj, self.target_collection) - if target is not None: - return self._scalar_get(target) - else: - return None + return self._scalar_get(target) else: try: # If the owning instance is reborn (orm session resurrect, @@ -291,7 +288,8 @@ class AssociationProxy(interfaces._InspectionAttr): def _default_getset(self, collection_class): attr = self.value_attr - getter = operator.attrgetter(attr) + _getter = operator.attrgetter(attr) + getter = lambda target: _getter(target) if target is not None else None if collection_class is dict: setter = lambda o, k, v: setattr(o, attr, v) else: |