summaryrefslogtreecommitdiff
path: root/lib/sqlalchemy/orm/mapper.py
diff options
context:
space:
mode:
authorMike Bayer <mike_mp@zzzcomputing.com>2022-04-19 21:06:41 -0400
committerMike Bayer <mike_mp@zzzcomputing.com>2022-04-27 14:46:36 -0400
commitad11c482e2233f44e8747d4d5a2b17a995fff1fa (patch)
tree57f8ddd30928951519fd6ac0f418e9cbf8e65610 /lib/sqlalchemy/orm/mapper.py
parent033d1a16e7a220555d7611a5b8cacb1bd83822ae (diff)
downloadsqlalchemy-ad11c482e2233f44e8747d4d5a2b17a995fff1fa.tar.gz
pep484 ORM / SQL result support
after some experimentation it seems mypy is more amenable to the generic types being fully integrated rather than having separate spin-off types. so key structures like Result, Row, Select become generic. For DML Insert, Update, Delete, these are spun into type-specific subclasses ReturningInsert, ReturningUpdate, ReturningDelete, which is fine since the "row-ness" of these constructs doesn't happen until returning() is called in any case. a Tuple based model is then integrated so that these objects can carry along information about their return types. Overloads at the .execute() level carry through the Tuple from the invoked object to the result. To suit the issue of AliasedClass generating attributes that are dynamic, experimented with a custom subclass AsAliased, but then just settled on having aliased() lie to the type checker and return `Type[_O]`, essentially. will need some type-related accessors for with_polymorphic() also. Additionally, identified an issue in Update when used "mysql style" against a join(), it basically doesn't work if asked to UPDATE two tables on the same column name. added an error message to the specific condition where it happens with a very non-specific error message that we hit a thing we can't do right now, suggest multi-table update as a possible cause. Change-Id: I5eff7eefe1d6166ee74160b2785c5e6a81fa8b95
Diffstat (limited to 'lib/sqlalchemy/orm/mapper.py')
-rw-r--r--lib/sqlalchemy/orm/mapper.py13
1 files changed, 6 insertions, 7 deletions
diff --git a/lib/sqlalchemy/orm/mapper.py b/lib/sqlalchemy/orm/mapper.py
index b37c080ea..083035093 100644
--- a/lib/sqlalchemy/orm/mapper.py
+++ b/lib/sqlalchemy/orm/mapper.py
@@ -96,7 +96,6 @@ if TYPE_CHECKING:
from .descriptor_props import Synonym
from .events import MapperEvents
from .instrumentation import ClassManager
- from .path_registry import AbstractEntityRegistry
from .path_registry import CachingEntityRegistry
from .properties import ColumnProperty
from .relationships import Relationship
@@ -108,10 +107,10 @@ if TYPE_CHECKING:
from ..sql.base import ReadOnlyColumnCollection
from ..sql.elements import ColumnClause
from ..sql.elements import ColumnElement
+ from ..sql.elements import KeyedColumnElement
from ..sql.schema import Column
from ..sql.schema import Table
from ..sql.selectable import FromClause
- from ..sql.selectable import TableClause
from ..sql.util import ColumnAdapter
from ..util import OrderedSet
@@ -161,7 +160,7 @@ _CONFIGURE_MUTEX = threading.RLock()
@log.class_logger
class Mapper(
ORMFromClauseRole,
- ORMEntityColumnsClauseRole,
+ ORMEntityColumnsClauseRole[_O],
MemoizedHasCacheKey,
InspectionAttr,
log.Identified,
@@ -1006,7 +1005,7 @@ class Mapper(
"""
- polymorphic_on: Optional[ColumnElement[Any]]
+ polymorphic_on: Optional[KeyedColumnElement[Any]]
"""The :class:`_schema.Column` or SQL expression specified as the
``polymorphic_on`` argument
for this :class:`_orm.Mapper`, within an inheritance scenario.
@@ -1699,10 +1698,10 @@ class Mapper(
instrument = True
key = getattr(col, "key", None)
if key:
- if self._should_exclude(col.key, col.key, False, col):
+ if self._should_exclude(key, key, False, col):
raise sa_exc.InvalidRequestError(
"Cannot exclude or override the "
- "discriminator column %r" % col.key
+ "discriminator column %r" % key
)
else:
self.polymorphic_on = col = col.label("_sa_polymorphic_on")
@@ -2948,7 +2947,7 @@ class Mapper(
def identity_key_from_row(
self,
- row: Optional[Union[Row, RowMapping]],
+ row: Optional[Union[Row[Any], RowMapping]],
identity_token: Optional[Any] = None,
adapter: Optional[ColumnAdapter] = None,
) -> _IdentityKeyType[_O]: