diff options
| author | Mike Bayer <mike_mp@zzzcomputing.com> | 2017-09-04 16:21:14 -0400 |
|---|---|---|
| committer | Mike Bayer <mike_mp@zzzcomputing.com> | 2017-09-04 18:55:30 -0400 |
| commit | 130f31ca79c7b40b2cb8aa1a4af7049408074d12 (patch) | |
| tree | 503370647ea6d78bbc38e4e5e6c3343bdc710136 /lib | |
| parent | 65680b2343ef421a62582e23e2b35293732933ad (diff) | |
| download | sqlalchemy-130f31ca79c7b40b2cb8aa1a4af7049408074d12.tar.gz | |
Check for non-mapped property in synonym
An :class:`.InvalidRequestError` is raised when a :func:`.synonym`
is used against an attribute that is not against a :class:`.MapperProperty`,
such as an association proxy. Previously, a recursion overflow would
occur trying to locate non-existent attributes.
Change-Id: If2ce38c429a69951df4c94b71b74edbd59d775e3
Fixes: #4067
Diffstat (limited to 'lib')
| -rw-r--r-- | lib/sqlalchemy/orm/descriptor_props.py | 13 |
1 files changed, 12 insertions, 1 deletions
diff --git a/lib/sqlalchemy/orm/descriptor_props.py b/lib/sqlalchemy/orm/descriptor_props.py index 9afdbf693..b9f016b42 100644 --- a/lib/sqlalchemy/orm/descriptor_props.py +++ b/lib/sqlalchemy/orm/descriptor_props.py @@ -594,7 +594,18 @@ class SynonymProperty(DescriptorProperty): @util.memoized_property def _proxied_property(self): - return getattr(self.parent.class_, self.name).property + attr = getattr(self.parent.class_, self.name) + if not hasattr(attr, 'property') or not \ + isinstance(attr.property, MapperProperty): + raise sa_exc.InvalidRequestError( + """synonym() attribute "%s.%s" only supports """ + """ORM mapped attributes, got %r""" % ( + self.parent.class_.__name__, + self.name, + attr + ) + ) + return attr.property def _comparator_factory(self, mapper): prop = self._proxied_property |
