John Huang wrote:
> Hi,
>
> I recently upgraded my system from SA 0.3.11 to 0.5.8, and I found
> that the behaviour for expiring instances has changed in terms of how
> much data gets retrieved upon attribute access. For instance,
>
> # One User can have many groups
> mapper(User, user_tbl, properties={'groups':relation(Group, ...,
> lazy=False, ...)})
>
> user_inst = session.query(User).first()
> session.expire(user_inst)
> # name is a scalar attribute
> # SA 0.3.11 will also eagerload User.groups relation, SA 0.5.8 will
> only reload scalar attributes
> user_inst.name
> # SA 0.3.11 will not hit the db, SA 0.5.8 will hit the db
> user_inst.groups
>
>
> AFAICT, expiring user_inst in SA 0.3.11 would create an instance-wide
> trigger so that the next attribute access would refresh the entire
> instance based on its primary mapper. However, in SA 0.5.8 (introduced
> in 0.4.1?) the functionality to expire specific attributes and this
> behaviour no longer exists. According to the docs, eager relationships
> should all be repopulated after an expired instance's attribute has
> been accessed, but this seems to be no longer the case. Is there any
> way I can recreate this behaviour?you can certainly expire specific attributes by passing a list of their names to expire: sess.expire(inst, ['foo', 'bar', 'bat']) in modern versions of SQLAlchemy calling session.refresh(instance) should reload attributes in the same way that a regular query.get() does which would include eager relationships loaded via join. the phrase "eager relationships will be repopulated" in the main docs for expire/refresh overall are inaccurate and misleading so I've added ticket 1762 to remove that language. > > -- > You received this message because you are subscribed to the Google Groups > "sqlalchemy" group. > To post to this group, send email to [email protected]. > To unsubscribe from this group, send email to > [email protected]. > For more options, visit this group at > http://groups.google.com/group/sqlalchemy?hl=en. > > -- You received this message because you are subscribed to the Google Groups "sqlalchemy" group. To post to this group, send email to [email protected]. To unsubscribe from this group, send email to [email protected]. For more options, visit this group at http://groups.google.com/group/sqlalchemy?hl=en.
