Re: [Sqlalchemy-tickets] [sqlalchemy] #2501: the DELETE before INSERT problem
Brought to you by:
zzzeek
|
From: sqlalchemy <mi...@zz...> - 2013-10-25 11:55:07
|
#2501: the DELETE before INSERT problem
------------------------------+---------------------------------------
Reporter: zzzeek | Owner: zzzeek
Type: defect | Status: new
Priority: high | Milestone: 0.9.xx
Component: orm | Severity: very major - up to 2 days
Resolution: | Keywords:
Progress State: needs tests |
------------------------------+---------------------------------------
Comment (by schlamar):
Another update: there are some issues with association proxy handling and
doing flush when the object is not yet fully created (similar to #2809).
So here is a fixed version for the code above:
{{{
#!python
def fix_order_by_constraint(session, obj, field, value):
setattr(obj, field, list())
session.flush() # possibly trigger delete cascade
for v in value:
state = inspection.inspect(v)
if state.deleted:
orm.make_transient(v) # put it back to life
# reset order by fields
for attr in get_order_by_properties(type(obj), field):
if hasattr(v, attr):
setattr(v, attr, None)
value = [get_related_obj(session, obj, v, field) for v in value]
if obj.id:
fix_order_by_constraint(session, obj, field, value)
setattr(obj, field, value)
}}}
--
Ticket URL: <http://www.sqlalchemy.org/trac/ticket/2501#comment:15>
sqlalchemy <http://www.sqlalchemy.org/>
The Database Toolkit for Python
|