diff options
author | Mike Bayer <mike_mp@zzzcomputing.com> | 2020-03-21 17:26:24 -0400 |
---|---|---|
committer | Mike Bayer <mike_mp@zzzcomputing.com> | 2020-03-22 11:47:59 -0400 |
commit | becab22dcbe9d68b0671a9246e022c9810f7e319 (patch) | |
tree | e9dee7d56ca0509ee08ffde195eb2f0791e9f158 /lib/sqlalchemy/orm/loading.py | |
parent | a25e2e02e108551d2910171202fd91fdaeb8162c (diff) | |
download | sqlalchemy-becab22dcbe9d68b0671a9246e022c9810f7e319.tar.gz |
Test instance for matching class hierarchy on get_from_identity
Fixed issue where a lazyload that uses session-local "get" against a target
many-to-one relationship where an object with the correct primary key is
present, however it's an instance of a sibling class, does not correctly
return None as is the case when the lazy loader actually emits a load for
that row.
Fixes: #5210
Change-Id: I89f9946cfeba61d89a272435f76a5a082b1da30c
Diffstat (limited to 'lib/sqlalchemy/orm/loading.py')
-rw-r--r-- | lib/sqlalchemy/orm/loading.py | 5 |
1 files changed, 4 insertions, 1 deletions
diff --git a/lib/sqlalchemy/orm/loading.py b/lib/sqlalchemy/orm/loading.py index c3d4773cd..49c71e5b2 100644 --- a/lib/sqlalchemy/orm/loading.py +++ b/lib/sqlalchemy/orm/loading.py @@ -161,7 +161,7 @@ def merge_result(query, iterator, load=True): session.autoflush = autoflush -def get_from_identity(session, key, passive): +def get_from_identity(session, mapper, key, passive): """Look up the given key in the given session's identity map, check the object for expired state if found. @@ -171,6 +171,9 @@ def get_from_identity(session, key, passive): state = attributes.instance_state(instance) + if mapper.inherits and not state.mapper.isa(mapper): + return attributes.PASSIVE_CLASS_MISMATCH + # expired - ensure it still exists if state.expired: if not passive & attributes.SQL_OK: |