force object to be `dirty` in sqlalchemy

后端 未结 2 753
遥遥无期
遥遥无期 2020-12-18 21:25

Is there a way to force an object mapped by sqlalchemy to be considered dirty? For example, given the context of sqlalchemy\'s Object Relational Tutorial the p

2条回答
  •  情书的邮戳
    2020-12-18 21:55

    The flag_modified approach works if one know that attribute have a value present. SQLAlchemy documentation states:

    Mark an attribute on an instance as ‘modified’.

    This sets the ‘modified’ flag on the instance and establishes an unconditional change event for the given attribute. The attribute must have a value present, else an InvalidRequestError is raised.

    Starting with version 1.2, if one wants to mark an entire instance then flag_dirty is the solution:

    Mark an instance as ‘dirty’ without any specific attribute mentioned.

提交回复
热议问题