Hi there,
Where I work, in our data model, we'd have several the opportunity to have
primary keys defined has a composite of something + an enum value. Though
because sqlalchemy requises
that primary keys can be sorted, it is not possible to define such primary keys.
Indeed, in Python, enums are not sortablle. Which is fine by us and, though we
could implemented some kind of ordre, to keep the behavior of enum types
consistent between those use in a table and those that are not, we'd rater not
do that. And yes, some might argue that this is a de-normalization and hence is
evil, but we find it handy enough to accept corrupting our souls...
If we do define such primary keys we end-up with the following error:
[2019-01-29T18:56:24.936Z app.py:35986 MainProcess session.py:400 ]
ERR APIException during a database transaction: . The database transaction will
be roll backed
Traceback (most recent call last):
File "~/.repositories/project/static_api/repository/zone.py", line 175, in
delete_zone
zone_to_delete.delete()
File "~/.repositories/project/models/zone.py", line 1851, in delete
super(Zone, self).delete()
File "~/.repositories/project/orm/declarative_base.py", line 325, in delete
return get_session().delete(self, **kwargs)
File "~/.repositories/project/orm/session.py", line 115, in delete
self.flush()
File "~/.repositories/project/orm/utils.py", line 289, in
retry_on_deadlock_decorator
return wrapped(*args, **kwargs)
File "~/.repositories/project/orm/session.py", line 188, in flush
return super(EtlSession, self).flush(objects)
File
"~/.virtualenvs/project-py35/lib/python3.5/site-packages/sqlalchemy/orm/session.py",
line 2139, in flush
self._flush(objects)
File
"~/.virtualenvs/project-py35/lib/python3.5/site-packages/sqlalchemy/orm/session.py",
line 2259, in _flush
transaction.rollback(_capture_exception=True)
File
"~/.virtualenvs/project-py35/lib/python3.5/site-packages/sqlalchemy/util/langhelpers.py",
line 66, in __exit__
compat.reraise(exc_type, exc_value, exc_tb)
File
"~/.virtualenvs/project-py35/lib/python3.5/site-packages/sqlalchemy/util/compat.py",
line 187, in reraise
raise value
File
"~/.virtualenvs/project-py35/lib/python3.5/site-packages/sqlalchemy/orm/session.py",
line 2223, in _flush
flush_context.execute()
File
"~/.virtualenvs/project-py35/lib/python3.5/site-packages/sqlalchemy/orm/unitofwork.py",
line 389, in execute
rec.execute(self)
File
"~/.virtualenvs/project-py35/lib/python3.5/site-packages/sqlalchemy/orm/unitofwork.py",
line 577, in execute
uow
File
"~/.virtualenvs/project-py35/lib/python3.5/site-packages/sqlalchemy/orm/persistence.py",
line 243, in delete_obj
uowtransaction))
File
"~/.virtualenvs/project-py35/lib/python3.5/site-packages/sqlalchemy/orm/persistence.py",
line 357, in _organize_states_for_delete
states):
File
"~/.virtualenvs/project-py35/lib/python3.5/site-packages/sqlalchemy/orm/persistence.py",
line 1108, in _connections_for_states
for state in _sort_states(states):
File
"~/.virtualenvs/project-py35/lib/python3.5/site-packages/sqlalchemy/orm/persistence.py",
line 1130, in _sort_states
sorted(persistent, key=lambda q: q.key[1])
TypeError: unorderable types: _EnumSymbol() < _EnumSymbol()
This is not à New issue, see reference below. It is mentioned there that this
may be made optional. So what would be the status of this ? I understand this
is not an arbitrary choice (a post mentions preventing deadlocks). What would
be the trade offs of such an options ?
https://groups.google.com/forum/#!searchin/sqlalchemy/primary$20key$20sortable%7Csort:date/sqlalchemy/mWbr-Tw4wvU/QXFYH2rRgFsJ
Thanks for enlightening us.
--
SQLAlchemy -
The Python SQL Toolkit and Object Relational Mapper
http://www.sqlalchemy.org/
To post example code, please provide an MCVE: Minimal, Complete, and Verifiable
Example. See http://stackoverflow.com/help/mcve for a full description.
---
You received this message because you are subscribed to the Google Groups
"sqlalchemy" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To post to this group, send email to [email protected].
Visit this group at https://groups.google.com/group/sqlalchemy.
To view this discussion on the web visit
https://groups.google.com/d/msgid/sqlalchemy/7a749928-b3e7-42e2-b428-f8d76000a881%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.