Thank you! Den måndag 25 september 2017 kl. 15:38:59 UTC+2 skrev Mike Bayer: > > On Mon, Sep 25, 2017 at 8:29 AM, Levon Saldamli <levo...@gmail.com > <javascript:>> wrote: > > I have an application which listens for before_flush events and does > some > > side effects when column values are deleted. But in some cases the > history > > for an attribute is empty even though it has been deleted. For example: > > > > person = Person(address="VALUE1") > > > > self.session.add(person) > > self.session.flush() > > #self.session.commit() > > > > # Without the next line, deletion of VALUE1 is not registered if > committed > > above > > #assert person.address > > > > person.address = None > > self.session.commit() > > > > > > Here, "VALUE1" is registered as deleted in the history only if: > > > > flush is called but not commit, or > > person.address is accessed before it is set to None > > > > Is this a bug or is it expected? > > it is expected, the ORM does not waste a whole SQL round trip to load > "VALUE1" that is only to be discarded in the vast majority of cases. > If you want that SQL round trip to occur, set active_history=True on > the attribute: > > > http://docs.sqlalchemy.org/en/latest/orm/mapping_columns.html?highlight=active_history#using-column-property-for-column-level-options > > > > http://docs.sqlalchemy.org/en/latest/orm/mapping_columns.html?highlight=active_history#sqlalchemy.orm.column_property.params.active_history > > > > > > > > > > > A complete example is attached with some prints that show the attribute > > state. > > > > > > SQLAlchemy version 1.1.14 > > python version 3.6.2 [GCC 4.2.1 Compatible Apple LLVM 8.1.0 > > (clang-802.0.42)] > > > > > > Best regards > > > > Levon Saldamli > > > > -- > > SQLAlchemy - > > The Python SQL Toolkit and Object Relational Mapper > > > > http://www.sqlalchemy.org/ > > > > To post example code, please provide an MCVE: Minimal, Complete, and > > Verifiable Example. See http://stackoverflow.com/help/mcve for a full > > description. > > --- > > 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+...@googlegroups.com <javascript:>. > > To post to this group, send email to sqlal...@googlegroups.com > <javascript:>. > > Visit this group at https://groups.google.com/group/sqlalchemy. > > For more options, visit https://groups.google.com/d/optout. >
-- SQLAlchemy - The Python SQL Toolkit and Object Relational Mapper http://www.sqlalchemy.org/ To post example code, please provide an MCVE: Minimal, Complete, and Verifiable Example. See http://stackoverflow.com/help/mcve for a full description. --- 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 https://groups.google.com/group/sqlalchemy. For more options, visit https://groups.google.com/d/optout.