New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Another case of illegal sorting in Python 3 #4232
Comments
Michael Bayer (@zzzeek) wrote: I thought I had this in the docs but it may have been removed, primary key values must be comparable. ill try to look to see why that's no longer in the docs (and confirm that it was, at some point) |
Michael Bayer (@zzzeek) wrote: this will raise a nicer exception, but doesn't "fix" anything for you, you need to put an |
Changes by Michael Bayer (@zzzeek):
|
Chris Wilson (@qris1) wrote: Thanks for the quick response! I couldn't find anything about this restriction in the docs. Would it be hard to remove the need for sortability? |
Michael Bayer (@zzzeek) wrote:
that's another thing I've definitely written about and can now find nowhere, when you run a bunch of UPDATE statements you want the ordering of the rows to be deterministic to minimize the chance of deadlocks with other transactions. Else if transaction A wants to update row 5 then row 7, transaction B wants to update row 7 then 5, deadlock. |
Michael Bayer (@zzzeek) wrote:
any database primary key value is sortable because it has to be indexed so it makes sense your in-python object should be sortable in some way, just stick an |
Michael Bayer (@zzzeek) wrote: Raise informative exception for non-sortable PK An informative exception is re-raised when a primary key value is not Change-Id: Ia186968982dcd1234b82f2e701fefa2a1668a7e4 → 036cdbe |
Changes by Michael Bayer (@zzzeek):
|
Migrated issue, originally created by Chris Wilson (@qris1)
Similar to #2228, but this one occurs when removing multiple objects from a session (deleting from the database) in a single commit, and the primary key contains an object which has no sort order defined, such as an Enum.
If there are multiple persistent objects to be deleted, then
_sort_states
inpersistence.py
wants to sort them, and it uses the identity key to do so. But if it contains non-comparable objects, this will fail.I'm not sure exactly why we want to "sort the states" here. But if the sort order is arbitrary then we could just sort by ID (or not sort them at all?).
I've seen this on Postgres 10 and SQLite (demo below).
The resulting error is:
The text was updated successfully, but these errors were encountered: