diff options
author | mike bayer <mike_mp@zzzcomputing.com> | 2020-04-20 15:31:05 +0000 |
---|---|---|
committer | Gerrit Code Review <gerrit@bbpush.zzzcomputing.com> | 2020-04-20 15:31:05 +0000 |
commit | fe35828eefc00e12e01df25f6fd942eecde1a686 (patch) | |
tree | 763164c163728d7faa809df56a5e5e6b98bb1b4b /lib | |
parent | 50cee43fbcbfba8a630007ce4ff867c6b913f20b (diff) | |
parent | 430ce5eab26d46301ae741f9068f13ba09907d8e (diff) | |
download | sqlalchemy-fe35828eefc00e12e01df25f6fd942eecde1a686.tar.gz |
Merge "Raise informative error when non-object m2o comparison used"
Diffstat (limited to 'lib')
-rw-r--r-- | lib/sqlalchemy/orm/relationships.py | 13 |
1 files changed, 12 insertions, 1 deletions
diff --git a/lib/sqlalchemy/orm/relationships.py b/lib/sqlalchemy/orm/relationships.py index 7d33c4649..6ac56a324 100644 --- a/lib/sqlalchemy/orm/relationships.py +++ b/lib/sqlalchemy/orm/relationships.py @@ -1621,8 +1621,19 @@ class RelationshipProperty(StrategizedProperty): alias_secondary=True, ): if state is not None: - state = attributes.instance_state(state) + try: + state = inspect(state) + except sa_exc.NoInspectionAvailable: + state = None + if state is None or not getattr(state, "is_instance", False): + raise sa_exc.ArgumentError( + "Mapped instance expected for relationship " + "comparison to object. Classes, queries and other " + "SQL elements are not accepted in this context; for " + "comparison with a subquery, " + "use %s.has(**criteria)." % self + ) reverse_direction = not value_is_parent if state is None: |