On Mon, Jun 24, 2019, at 6:12 AM, Nico C. wrote: > 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 you aren't worried about a lack of purity on the SQL side, then why can't you also just add a __lt__() to your Enum object? That would allow your program to work right now and this is what you'd need to do for now. > 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 ? The official issue for Enum as primary key without the need to apply an __lt__() method to the Enum is at: https://github.com/sqlalchemy/sqlalchemy/issues/4285 Don't worry that it's closed at the moment, feel free to reopen this issue if you are motivated to provide a pull request with tests as it's labeled that motivated volunteers are requested. The description of the feature is: a pull request that includes well written tests may be accepted. PR would add a new method TypeEngine.value_sortkey(value), and then the persistence._sort_states() method would call upon this function to work on top of the values pulled from the "persistent" set, and the Enum datatype would likely allow a new callable to be passed that implements this (or it somehow knows how to build one from a pep-435 style collection). let me know if this is important enough that you can donate some programming time for it and I will help you every step of the way to implement. > > 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 sqlalchemy+unsubscr...@googlegroups.com. > To post to this group, send email to sqlalchemy@googlegroups.com. > 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. > -- 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 sqlalchemy+unsubscr...@googlegroups.com. To post to this group, send email to sqlalchemy@googlegroups.com. 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/10c39780-6272-43af-9b33-711c67719998%40www.fastmail.com. For more options, visit https://groups.google.com/d/optout.