On Mon, Jun 24, 2019, at 1:24 PM, Nico C. wrote:
> One of the many reasons not to implement __lt__, is that the types are used 
> with different databases. Those have had very different stories, especially 
> enum labels may not have been added in the same order. Hence, defining and 
> order may lead people to rely on it. But, on either side (postgresql or 
> python) that may yield different behavior depending on the underlying db.

OK given PostgreSQL's exception case that ENUMs are sorted in creation order, 
which is not what any other database does, this is a point for purity. But if 
you want the ORM to not sort UPDATEs at all, then you're going to open yourself 
up to deadlocks. So it has to sort by something and it does not need to match 
what the database would sort as since that's not the purpose of this particular 
sort. 

> 
> We could sort this out (but may not really be worth the pain, on a system 
> that is in production 24/7). But we also have had bugs in the past, that 
> boiled down to ill defined or non-sensical orders (e.g. inadvertently sorting 
> objects based on their memory addresses [thank Python3 for fixing that]) That 
> can work for suprisingly long periods of time, until it doesn't. So, though 
> it may sound a bit too phisolophical or just silly, I'd rather not implement 
> orders that don't exist. As Python3 chose to do (e.g. objects no longer have 
> an implicit order)

there is an ordering that exists though, it's just that due to PostgreSQL it 
has to pull in a server-side algorithm to do it which I am not proposing we 
attempt to implement.


> 
> Our use case is more about partitioning tables. The fact that an entity 
> belongs to one partition or another doesn't make the entity greater or lower 
> than any other.
> 
> Not being able to add the enum in the primary key often means we have to 
> handle unique constraints manually, add surrogate keys, which are on some 
> large tables uselessly space and time consuming.

If you are using an ENUM as a primary key then that suggests there are a 
limited number of rows here, if they are in fact UPDATED infrequently you can 
still use these objects as ORM objects, you'd just need to use the bulk update 
interface until the SQLAlchemy feature can be implemented.

> 
> I've read the issue. Our code base having been started quite a while back, 
> we're using your enum recipe. We have implemented a few other behavior on top 
> of that, that has delayed our migration to plain Python enums. Not sure if it 
> would be worth doing in that setting or be a valid motivation to do the 
> change. I may have some time, later in the summer (end of July, August). No 
> promises.

You've reminded me that PG enums sort by insert order and not string name so I 
continue to favor a feature that detaches the sorting from the Enum value 
itself.

The feature is implemented in the comment at 
https://github.com/sqlalchemy/sqlalchemy/issues/4285#issuecomment-505144511 . 
It needs one additional test in test/sql/test_types.py -> EnumTest to verify 
the Enum side of the feature is working. Please add this test, review the code 
I've added, make sure the patch works for your use case, and send a PR, thanks.




> 
> Anyhow, thank you for your answer.
> 
> Regards,
> Nicolas. 
> 
> -- 
> 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/e4fdb93a-3db5-4e27-bcb4-31cc61863d65%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/727b7ae4-e922-4abb-9489-12d60d98ad43%40www.fastmail.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to