Add support for InstrumentedAttributes in get_mapper
This commit is contained in:
@@ -83,6 +83,8 @@ def get_mapper(mixed):
|
||||
mixed = mixed.element
|
||||
if isinstance(mixed, AliasedInsp):
|
||||
return mixed.mapper
|
||||
if isinstance(mixed, sa.orm.attributes.InstrumentedAttribute):
|
||||
mixed = mixed.class_
|
||||
if isinstance(mixed, sa.Table):
|
||||
mappers = [
|
||||
mapper for mapper in mapperlib._mapper_registry
|
||||
|
@@ -42,6 +42,11 @@ class TestGetMapper(object):
|
||||
sa.inspect(self.Building)
|
||||
)
|
||||
|
||||
def test_instrumented_attribute(self):
|
||||
assert (
|
||||
get_mapper(self.Building.id) == sa.inspect(self.Building)
|
||||
)
|
||||
|
||||
def test_table_alias(self):
|
||||
alias = sa.orm.aliased(self.Building.__table__)
|
||||
assert (
|
||||
|
Reference in New Issue
Block a user