diff options
| author | Federico Caselli <cfederico87@gmail.com> | 2021-05-12 21:09:41 +0200 |
|---|---|---|
| committer | Mike Bayer <mike_mp@zzzcomputing.com> | 2021-05-20 16:17:46 -0400 |
| commit | e26487e234e4192db7e75cedf029df6de83f3415 (patch) | |
| tree | fb1539d564493e02bab24e02b20bd133dd515816 /lib/sqlalchemy/orm/relationships.py | |
| parent | 71a858817cb8c11451ae577c61329f4239fab46b (diff) | |
| download | sqlalchemy-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.py | 7 |
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 |
