On Mon, Mar 5, 2018 at 1:35 AM, Tolstov Sergey <[email protected]> wrote: > On my project, i use __getattr__ for adding column deifinition to object > class > Such as: > > def __getattr__(self,attr): > ... > my_load_function(...) > session.refresh(self) > ... > return getattr(self,attr) >
I realized you are actually adding a new mapped attribute as the __getattr__ is called. This is a very strange pattern. > It works, but refresh loses changes on this object. I cannot flush, because > it used for another function. do session.expire() on the attribute instead. the getattr() will load it. > > I found solution > session.refresh(self, attribute_names=['attr_name']) > > But it will raise exception > sqlalchemy.exc.InvalidRequestError: No column-based properties specified for > refresh operation. Use session.expire() to reload collections and related > items.] > > I already tried use session.expire(self) and session.expire(self, > attribute_names=['attr_name'])) before and after refresh, but nothing > changed > > Can someone help me with this eror? > > -- > 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 [email protected]. > To post to this group, send email to [email protected]. > 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 [email protected]. To post to this group, send email to [email protected]. Visit this group at https://groups.google.com/group/sqlalchemy. For more options, visit https://groups.google.com/d/optout.
