]> git.ipfire.org Git - thirdparty/sqlalchemy/sqlalchemy.git/commit
Implement type-level sorting for Enum; apply to ORM primary keys
authorNicolas CANIART <nicolas@caniart.net>
Thu, 22 Aug 2019 18:16:29 +0000 (14:16 -0400)
committerMike Bayer <mike_mp@zzzcomputing.com>
Tue, 27 Aug 2019 16:59:21 +0000 (12:59 -0400)
commit75b2518b2659796c885396fd0893dd7f9b19a9ef
treea7d67e8d62ab16306ae2881dfd1c944a69fd3eed
parent94385b031c1dac004ee4181cb5783328d740d110
Implement type-level sorting for Enum; apply to ORM primary keys

Added support for the use of an :class:`.Enum` datatype using Python
pep-435 enumeration objects as values for use as a primary key column
mapped by the ORM.  As these values are not inherently sortable, as
required by the ORM for primary keys, a new
:attr:`.TypeEngine.sort_key_function` attribute is added to the typing
system which allows any SQL type to  implement a sorting for Python objects
of its type which is consulted by the unit of work.   The :class:`.Enum`
type then defines this using the  database value of a given enumeration.
The sorting scheme can be  also be redefined by passing a callable to the
:paramref:`.Enum.sort_key_function` parameter.  Pull request courtesy
Nicolas Caniart.

Fixes: #4285
Closes: #4816
Pull-request: https://github.com/sqlalchemy/sqlalchemy/pull/4816
Pull-request-sha: 42266b766c1e462d5b8a409cda05d33dea13bd34

Change-Id: Iadcc16173c1ba26ffac5830db57743a4cb987c55
doc/build/changelog/unreleased_13/4285.rst [new file with mode: 0644]
lib/sqlalchemy/orm/mapper.py
lib/sqlalchemy/orm/persistence.py
lib/sqlalchemy/sql/sqltypes.py
lib/sqlalchemy/sql/type_api.py
test/orm/test_mapper.py
test/orm/test_naturalpks.py
test/orm/test_unitofwork.py
test/sql/test_types.py