--- /dev/null
+.. change::
+ :tags: bug, orm
+ :tickets: 7591
+
+ Fixed issue in :meth:`_orm.Session.bulk_save_mappings` where the sorting
+ that takes place when the ``preserve_order`` parameter is set to False
+ would sort partially on ``Mapper`` objects, which is rejected in Python
+ 3.11.
+
"""
- def key(state):
- return (state.mapper, state.key is not None)
-
obj_states = (attributes.instance_state(obj) for obj in objects)
+
if not preserve_order:
- obj_states = sorted(obj_states, key=key)
+ # the purpose of this sort is just so that common mappers
+ # and persistence states are grouped together, so that groupby
+ # will return a single group for a particular type of mapper.
+ # it's not trying to be deterministic beyond that.
+ obj_states = sorted(
+ obj_states,
+ key=lambda state: (id(state.mapper), state.key is not None),
+ )
- for (mapper, isupdate), states in itertools.groupby(obj_states, key):
+ def grouping_key(state):
+ return (state.mapper, state.key is not None)
+
+ for (mapper, isupdate), states in itertools.groupby(
+ obj_states, grouping_key
+ ):
self._bulk_save_mappings(
mapper,
states,
from typing import TypeVar
from typing import Union
+from typing_extensions import NotRequired # noqa
+
from . import compat
_T = TypeVar("_T", bound=Any)
from typing_extensions import Concatenate # noqa
from typing_extensions import ParamSpec # noqa
-if compat.py311:
- from typing import NotRequired # noqa
-else:
- from typing_extensions import NotRequired # noqa
-
_T = TypeVar("_T")
install_requires =
importlib-metadata;python_version<"3.8"
greenlet != 0.4.17;(platform_machine=='aarch64' or (platform_machine=='ppc64le' or (platform_machine=='x86_64' or (platform_machine=='amd64' or (platform_machine=='AMD64' or (platform_machine=='win32' or platform_machine=='WIN32'))))))
- typing-extensions >= 4;python_version<"3.11"
+ typing-extensions >= 4
[options.extras_require]
asyncio =
pytest>=7.0.0rc1,<8
pytest-xdist
+ # note cython not working for 3.11 at all right now
+ git+https://github.com/python-greenlet/greenlet.git#egg=greenlet; python_version >= '3.11'
+
sqlite: .[aiosqlite]
sqlite_file: .[aiosqlite]
sqlite_file: .[sqlcipher]; python_version < '3.10'