--- /dev/null
+.. change::
+ :tags: bug, orm, typing
+ :tickets: 9256
+
+ Adjusted the type annotations for
+ :meth:`_orm.Session.bulk_insert_mappings` and
+ :meth:`_orm.Session.bulk_update_mappings` to accept a mapped class as well
+ as a :class:`_orm.Mapper`, matching the documented and runtime behavior of
+ these legacy methods.
from ._typing import OrmExecuteOptionsParameter
from .identity import IdentityMap
from .interfaces import ORMOption
- from .mapper import Mapper
from .query import Query
from .query import RowReturningQuery
from .session import _BindArguments
def bulk_insert_mappings(
self,
- mapper: Mapper[Any],
+ mapper: _EntityBindKey[Any],
mappings: Iterable[Dict[str, Any]],
return_defaults: bool = False,
render_nulls: bool = False,
)
def bulk_update_mappings(
- self, mapper: Mapper[Any], mappings: Iterable[Dict[str, Any]]
+ self, mapper: _EntityBindKey[Any], mappings: Iterable[Dict[str, Any]]
) -> None:
r"""Perform a bulk update of the given list of mapping dictionaries.
def bulk_insert_mappings(
self,
- mapper: Mapper[Any],
+ mapper: _EntityBindKey[Any],
mappings: Iterable[Dict[str, Any]],
return_defaults: bool = False,
render_nulls: bool = False,
)
def bulk_update_mappings(
- self, mapper: Mapper[Any], mappings: Iterable[Dict[str, Any]]
+ self, mapper: _EntityBindKey[Any], mappings: Iterable[Dict[str, Any]]
) -> None:
"""Perform a bulk update of the given list of mapping dictionaries.
def _bulk_save_mappings(
self,
- mapper: Mapper[_O],
+ mapper: _EntityBindKey[_O],
mappings: Union[Iterable[InstanceState[_O]], Iterable[Dict[str, Any]]],
*,
isupdate: bool,
from sqlalchemy import create_engine
from sqlalchemy import ForeignKey
from sqlalchemy import Integer
+from sqlalchemy import inspect
from sqlalchemy import MetaData
from sqlalchemy import Result
from sqlalchemy import Select
with sess.begin() as tx:
assert_type(tx, SessionTransaction)
+ # test #9256
+
+ sess.bulk_insert_mappings(User, [{"id": 1, "name": "u1"}])
+ sess.bulk_update_mappings(User, [{"id": 1, "name": "u1"}])
+ sess.bulk_insert_mappings(inspect(User), [{"id": 2, "name": "u2"}])
+ sess.bulk_update_mappings(inspect(User), [{"id": 2, "name": "u2"}])
+
# more result tests in typed_results.py