summaryrefslogtreecommitdiff
path: root/lib/sqlalchemy
diff options
context:
space:
mode:
authormike bayer <mike_mp@zzzcomputing.com>2021-05-21 15:18:15 +0000
committerGerrit Code Review <gerrit@ci3.zzzcomputing.com>2021-05-21 15:18:15 +0000
commitb2ab2bbf4faf508b3fa5749969019203a702786f (patch)
tree8acf963f97007aada72fc6219273874f30dd7b82 /lib/sqlalchemy
parent52f4d384b6236d00c07afa66ffb8ae2343a87b0f (diff)
parente26487e234e4192db7e75cedf029df6de83f3415 (diff)
downloadsqlalchemy-b2ab2bbf4faf508b3fa5749969019203a702786f.tar.gz
Merge "Detect back_populates referring to non-relationship"
Diffstat (limited to 'lib/sqlalchemy')
-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 5d87ef797..00a14b04c 100644
--- a/lib/sqlalchemy/orm/relationships.py
+++ b/lib/sqlalchemy/orm/relationships.py
@@ -2046,6 +2046,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