This is what I suggested originally, you set tn.editor_id to "2", then you run the same loop over and over again. the value of tn.editor_id does not change, and is not part of the parameters in the UPDATE statement. if you remove the column on update and look at the echoed SQL, the statements all look like this:
UPDATE tenant SET mtime=CURRENT_TIMESTAMP, descr=? WHERE tenant.id = ? as expected, editor_id is not present - it hasn't changed, so is not present in the SET clause. When you use onupdate=<something>, SQLAlchemy is being told to use this function to prepare a value for the editor_id column in the *absense* of any change. That your function is being called in the first place is an indicator that there otherwise would be no change made to this column. The value of "None" in the dictionary is there in preparation for the default function to be invoked and place something there; because the column has an ON UPDATE default, it means the column must unconditionally be in the SET clause of the UPDATE statement. So now the SET appears and it uses None because your function has no return value, hence is None in Python. So in this regard an onupdate default can't really be effectively used to effect no change on a column as it seems is the need here; the UPDATE statement has already been rendered with a SET clause including the column in question. At best it could return the value that's expected to be there, but the ORM's notion of the object is not really accessible at this level. the last moment you would have to validate what's to be sent as an UPDATE before the structure is fixed would be the before_update mapper event. The other option would be within the before_flush() event. On Mar 17, 2014, at 5:08 AM, Dirk Makowski <dirk.makow...@gmail.com> wrote: > A slightly improved version, where I activated the > onupdate=_validate_editor() check again to log an error if it finds editor_id > not set. > > -- > You received this message because you are subscribed to the Google Groups > "sqlalchemy" group. > To unsubscribe from this group and stop receiving emails from it, send an > email to sqlalchemy+unsubscr...@googlegroups.com. > To post to this group, send email to sqlalchemy@googlegroups.com. > Visit this group at http://groups.google.com/group/sqlalchemy. > For more options, visit https://groups.google.com/d/optout. > <check_editor_id.py> -- You received this message because you are subscribed to the Google Groups "sqlalchemy" group. To unsubscribe from this group and stop receiving emails from it, send an email to sqlalchemy+unsubscr...@googlegroups.com. To post to this group, send email to sqlalchemy@googlegroups.com. Visit this group at http://groups.google.com/group/sqlalchemy. For more options, visit https://groups.google.com/d/optout.