On Jul 31, 2007, at 11:30 AM, Paul Johnston wrote:
>
> Hi,
>
>>> Seems like a good time to bring up a slightly related problem. If
>>> you
>>> modify an object in a function providing a default value, the
>>> object is not flushed (unless you do that manually).
>>>
>> not sure i understand the scenario here, could you illustrate ?
>>
>>
> I've put a bit more explanation and a test case on ticket #703. I
> had a
> look at fixing it, but it seems like a tough one.
>
ok that exactly cannot be fixed, and i would suggest that you dont
use an ORM mapped class as a default value generator. The reason it
cannot is because once the flush() is proceeding, everything which is
to be inserted/updated/deleted has been laid out and placed into a
queue to be executed. Any changes to instrumented attributes which
occur *within* the flush is not going to get picked up - that train
has already left the station.
the way to do this pattern is to use straight SQL instead (note
however, the 'ctx' variable requires 0.4):
seq = Table('seq', m,
Column('seq', String(50), primary_key=True),
Column('nextval', Integer))
def newid(ctx):
id = ctx.connection.execute(select([seq.c.nextval],
seq.c.seq=='tbl', for_update=True)).scalar()
ctx.connection.execute(seq.update(values=[seq.c.nextval :
seq.c.nextval +1]))
return hex(id)
This way you also get fine-grained control over the seq table's locking.
However I do need to commit something to make that work so that will
be the ticket's resolution.
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"sqlalchemy" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at
http://groups.google.com/group/sqlalchemy?hl=en
-~----------~----~----~----~------~----~------~--~---