Update of orderinglist relationship when position is used in PK
Sometimes the only choice for primary key of objects in private relationship is parent ID and position in list pair. But update of such property doesn't work: property after flush contains other objects than where assigned to it.
Comments (12)
-
repo owner -
repo owner - changed milestone to 0.x.xx
- changed title to Update of orderinglist relationship when position is used in PK
- changed component to orm
-
reporter Sorry, I havn't seen the warning. I agree with you that sometimes it's not possible to meet unique constraint when order is changed (it's agruable for PK: we can see it as order change or just values swap). In my test case all objects in the assigned list are new, so I see no reason to handle it as reorder.
-
repo owner OK, it would take me some time to understand the issue and at the end it's probably some variant of that problem in any case, is there no way you can just work around this or attempt to fix ? that would be very helpful.
-
reporter I didn't find workaround yet.
-
repo owner my first observation is that you're expecting the "d" value to stay the same? I'm reading what ordering list does (I didn't write it) and it says: "automatically synchronize changes in list position onto a target scalar attribute." Doesn't that mean you at the very least need to provide "ordering_func" to do alphabetical ordering, and that you'd want this?
p.children = [Child(data='d')] assert p.children == [Child(data='a')]
-
reporter No,
'a'
,'b'
,'c'
, etc. are just handy values for testing to see what's going on. I need to keep the same order as it was when property was assigned. And I forced to use position is PK since there is no other candidate (all the rest fields are not unique, most are nullable) and using autoincremented id will increase database fragmentation on each update. Also don't want to use serialization (like pickle or JSON) since I have a field with foreign key constraint. -
repo owner oh, data is not the ordering attribute. totally confusing example, still having trouble understanding what the problem is. this is taking me all morning
-
repo owner it seems like the deletes of old records fails because as they are removed, their ordering position changes, so the primary keys are wrong and the rows are missed. This is exactly why the warning is there, I don't know how to solve this and I didn't write this extension in the first place. Please don't use primary keys with ordering list.
-
repo owner there's an issue with PK-based update + delete that's independent of this.
#3006 -
repo owner - changed status to resolved
your test case passes as is with
#3006resolved. -
repo owner - changed milestone to 1.x.xx
- Log in to comment
Haven't looked deeply yet, but I see "ordering list" and "primary key", a lot of these issues aren't fixable, I'm sure you've seen http://docs.sqlalchemy.org/en/rel_0_9/orm/extensions/orderinglist.html :
is this issue just another restatement of that? orderinglist only goes so far and I don't really have any great way to improve it in this regard.