|
10 | 10 | from sqlalchemy.orm.attributes import InstrumentedAttribute |
11 | 11 | from sqlalchemy.orm.exc import UnmappedInstanceError |
12 | 12 |
|
13 | | -try: |
14 | | - from sqlalchemy.orm.context import _ColumnEntity, _MapperEntity |
15 | | -except ImportError: # SQLAlchemy <1.4 |
16 | | - from sqlalchemy.orm.query import _ColumnEntity, _MapperEntity |
| 13 | +from sqlalchemy.orm.context import _ColumnEntity, _MapperEntity |
17 | 14 |
|
18 | 15 | from sqlalchemy.orm.session import object_session |
19 | 16 | from sqlalchemy.orm.util import AliasedInsp |
@@ -281,12 +278,9 @@ def get_mapper(mixed): |
281 | 278 | if isinstance(mixed, sa.orm.attributes.InstrumentedAttribute): |
282 | 279 | mixed = mixed.class_ |
283 | 280 | if isinstance(mixed, sa.Table): |
284 | | - if hasattr(mapperlib, '_all_registries'): |
285 | | - all_mappers = set() |
286 | | - for mapper_registry in mapperlib._all_registries(): |
287 | | - all_mappers.update(mapper_registry.mappers) |
288 | | - else: # SQLAlchemy <1.4 |
289 | | - all_mappers = mapperlib._mapper_registry |
| 281 | + all_mappers = set() |
| 282 | + for mapper_registry in mapperlib._all_registries(): |
| 283 | + all_mappers.update(mapper_registry.mappers) |
290 | 284 | mappers = [mapper for mapper in all_mappers if mixed in mapper.tables] |
291 | 285 | if len(mappers) > 1: |
292 | 286 | raise ValueError("Multiple mappers found for table '%s'." % mixed.name) |
@@ -449,11 +443,10 @@ def get_columns(mixed): |
449 | 443 | SA Table object, SA Mapper, SA declarative class, SA declarative class |
450 | 444 | instance or an alias of any of these objects |
451 | 445 | """ |
| 446 | + if isinstance(mixed, sa.SelectBase): |
| 447 | + return mixed.subquery().c |
452 | 448 | if isinstance(mixed, sa.sql.selectable.Selectable): |
453 | | - try: |
454 | | - return mixed.selected_columns |
455 | | - except AttributeError: # SQLAlchemy <1.4 |
456 | | - return mixed.c |
| 449 | + return mixed.c |
457 | 450 | if isinstance(mixed, sa.orm.util.AliasedClass): |
458 | 451 | return sa.inspect(mixed).mapper.columns |
459 | 452 | if isinstance(mixed, sa.orm.Mapper): |
@@ -520,10 +513,7 @@ def quote(mixed, ident): |
520 | 513 |
|
521 | 514 |
|
522 | 515 | def _get_query_compile_state(query): |
523 | | - if hasattr(query, '_compile_state'): |
524 | | - return query._compile_state() |
525 | | - else: # SQLAlchemy <1.4 |
526 | | - return query |
| 516 | + return query._compile_state() |
527 | 517 |
|
528 | 518 |
|
529 | 519 | def get_polymorphic_mappers(mixed): |
@@ -878,7 +868,4 @@ def naturally_equivalent(obj, obj2): |
878 | 868 |
|
879 | 869 |
|
880 | 870 | def _get_class_registry(class_): |
881 | | - try: |
882 | | - return class_.registry._class_registry |
883 | | - except AttributeError: # SQLAlchemy <1.4 |
884 | | - return class_._decl_class_registry |
| 871 | + return class_.registry._class_registry |
0 commit comments