summaryrefslogtreecommitdiff
path: root/lib/sqlalchemy/orm/relationships.py
diff options
context:
space:
mode:
authorFederico Caselli <cfederico87@gmail.com>2021-05-12 21:09:41 +0200
committerMike Bayer <mike_mp@zzzcomputing.com>2021-05-20 16:17:46 -0400
commite26487e234e4192db7e75cedf029df6de83f3415 (patch)
treefb1539d564493e02bab24e02b20bd133dd515816 /lib/sqlalchemy/orm/relationships.py
parent71a858817cb8c11451ae577c61329f4239fab46b (diff)
downloadsqlalchemy-e26487e234e4192db7e75cedf029df6de83f3415.tar.gz
Detect back_populates referring to non-relationship
Change-Id: Ic26d5d6d230d8d3209e6e42ff7752b59b8cb7b28
Diffstat (limited to 'lib/sqlalchemy/orm/relationships.py')
-rw-r--r--lib/sqlalchemy/orm/relationships.py7
1 files changed, 7 insertions, 0 deletions
diff --git a/lib/sqlalchemy/orm/relationships.py b/lib/sqlalchemy/orm/relationships.py
index 2ed9d859a..7e97962f4 100644
--- a/lib/sqlalchemy/orm/relationships.py
+++ b/lib/sqlalchemy/orm/relationships.py
@@ -2051,6 +2051,13 @@ class RelationshipProperty(StrategizedProperty):
def _add_reverse_property(self, key):
other = self.mapper.get_property(key, _configure_mappers=False)
+ if not isinstance(other, RelationshipProperty):
+ raise sa_exc.InvalidRequestError(
+ "back_populates on relationship '%s' refers to attribute '%s' "
+ "that is not a relationship. The back_populates parameter "
+ "should refer to the name of a relationship on the target "
+ "class." % (self, other)
+ )
# viewonly and sync_backref cases
# 1. self.viewonly==True and other.sync_backref==True -> error
# 2. self.viewonly==True and other.viewonly==False and