Overriding onupdate

45 views
Skip to first unread message

Sam Magister

unread,
Mar 9, 2009, 4:42:31 PM3/9/09
to sqlalchemy
Hi,

I have a column definition that looks like:

Column('is_cached', Boolean, onupdate=False, default=False,
nullable=False)

The onupdate feature works as advertised.

My issue is that I have a caching script that calls update() which
sets is_cached=True:
conn.execute(mytable.update().where(mytable.c.id==1).values
(is_cached=True))

However, onupdate, works too well in this case and sets
is_cached=False, negating the update which I intended.

I know it's possible to get around this by doing

conn.execute("UPDATE mytable SET is_cached=0 WHERE id=1")

since onupdate is not triggered by a straight SQL command.

However, using the straight SQL feels like a hack (and I have to think
about SQL injection vulnerabilities).

Is it possible to override onupdate values without resorting to
straight SQL?

Thanks,

Sam

Michael Bayer

unread,
Mar 9, 2009, 5:04:11 PM3/9/09
to sqlal...@googlegroups.com
specifying is_cached=True should work fine. does it work if you remove
the "onupdate" from the column ?

>
> Thanks,
>
> Sam
>
>
> >
>

Reply all
Reply to author
Forward
0 new messages