summaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
authorMike Bayer <mike_mp@zzzcomputing.com>2017-09-04 16:21:14 -0400
committerMike Bayer <mike_mp@zzzcomputing.com>2017-09-04 18:55:30 -0400
commit130f31ca79c7b40b2cb8aa1a4af7049408074d12 (patch)
tree503370647ea6d78bbc38e4e5e6c3343bdc710136 /test
parent65680b2343ef421a62582e23e2b35293732933ad (diff)
downloadsqlalchemy-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 'test')
-rw-r--r--test/orm/test_mapper.py25
1 files changed, 25 insertions, 0 deletions
diff --git a/test/orm/test_mapper.py b/test/orm/test_mapper.py
index 2392aa002..f39e174b0 100644
--- a/test/orm/test_mapper.py
+++ b/test/orm/test_mapper.py
@@ -1406,6 +1406,31 @@ class MapperTest(_fixtures.FixtureTest, AssertsCompiledSQL):
u = s.query(User).filter(User.y == 8).one()
eq_(u.y, 8)
+ def test_synonym_of_non_property_raises(self):
+ from sqlalchemy.ext.associationproxy import association_proxy
+
+ class User(object):
+ pass
+
+ users, Address, addresses = (
+ self.tables.users,
+ self.classes.Address,
+ self.tables.addresses)
+
+ mapper(User, users, properties={
+ 'y': synonym('x'),
+ 'addresses': relationship(Address)
+ })
+ mapper(Address, addresses)
+ User.x = association_proxy("addresses", "email_address")
+
+ assert_raises_message(
+ sa.exc.InvalidRequestError,
+ r'synonym\(\) attribute "User.x" only supports ORM mapped '
+ 'attributes, got .*AssociationProxy',
+ getattr, User.y, "property"
+ )
+
def test_synonym_column_location(self):
users, User = self.tables.users, self.classes.User