[sqlalchemy] Re: how to force a clean refresh of a lazy loaded attribute
Michael Bayer ha scritto: On Feb 25, 2007, at 9:03 AM, Manlio Perillo wrote: Michael Bayer ha scritto: On Feb 23, 2007, at 1:56 PM, Manlio Perillo wrote: Hi again. I have an object attribute loaded via lazy loader. This object is loaded in a transaction. Then, in another transaction, I ussue an update statement (via the sql module, not using the orm), that updates the table of the main object's attribute. The problem, now, is that I want to reload this attribute. I have tried, in a separate transaction: sess.update(obj) sess.expire(obj) One problem here is that the entire object is reloaded, and I do not want this. i think if you say delattr(obj, attributename), it will do a lazyload on the next run. Sorry, I have tested only sess.expire(obj). delattr(obj, attributename) does not works. OK, again, if you want the actual object that is *in* the lazy loaded collection to be reloaded, you have to issue an expire() or refresh() on at least that object. if the object is already in the session, the lazy load may still fire off but will only reload the instance that is already in the session. so you might want do instead do this (assuming its a lazy load collection - modify accordingly for a scalar attribute): for o in myinstance.somecollection: sess.expire(o) This works, thanks! However, for non scalar attribute, I would like to simply do: sess.expire(myinstance.somecollection) Regards Manlio Perillo --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups sqlalchemy group. To post to this group, send email to sqlalchemy@googlegroups.com 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 -~--~~~~--~~--~--~---
[sqlalchemy] Re: how to force a clean refresh of a lazy loaded attribute
you could certainly write a helper function if you find that you do this a lot. I'd be -1 on making it official, it just seems messy to me. (defining collection only as list is sucky; defining collection as anything you can iterate over is problematic because an instance that is itself in the session could define __iter__ and then your semantics are ambiguous.) On 2/26/07, Manlio Perillo [EMAIL PROTECTED] wrote: This works, thanks! However, for non scalar attribute, I would like to simply do: sess.expire(myinstance.somecollection) --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups sqlalchemy group. To post to this group, send email to sqlalchemy@googlegroups.com 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 -~--~~~~--~~--~--~---
[sqlalchemy] Re: how to force a clean refresh of a lazy loaded attribute
Michael Bayer ha scritto: On Feb 23, 2007, at 1:56 PM, Manlio Perillo wrote: Hi again. I have an object attribute loaded via lazy loader. This object is loaded in a transaction. Then, in another transaction, I ussue an update statement (via the sql module, not using the orm), that updates the table of the main object's attribute. The problem, now, is that I want to reload this attribute. I have tried, in a separate transaction: sess.update(obj) sess.expire(obj) One problem here is that the entire object is reloaded, and I do not want this. i think if you say delattr(obj, attributename), it will do a lazyload on the next run. Ok, it needs the latest version in trunk but now works. The other problem (maybe a bug?) is that the orm issue another query to reload the data from the database, but in the object I still find the old values! I have submitted a ticket for the last problem (#492). refresh-expire cascade had not yet been implemented, just added it in the trunk. Thanks! Regards Manlio Perillo --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups sqlalchemy group. To post to this group, send email to sqlalchemy@googlegroups.com 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 -~--~~~~--~~--~--~---
[sqlalchemy] Re: how to force a clean refresh of a lazy loaded attribute
Michael Bayer ha scritto: On Feb 23, 2007, at 1:56 PM, Manlio Perillo wrote: Hi again. I have an object attribute loaded via lazy loader. This object is loaded in a transaction. Then, in another transaction, I ussue an update statement (via the sql module, not using the orm), that updates the table of the main object's attribute. The problem, now, is that I want to reload this attribute. I have tried, in a separate transaction: sess.update(obj) sess.expire(obj) One problem here is that the entire object is reloaded, and I do not want this. i think if you say delattr(obj, attributename), it will do a lazyload on the next run. Sorry, I have tested only sess.expire(obj). delattr(obj, attributename) does not works. Regards Manlio Perillo --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups sqlalchemy group. To post to this group, send email to sqlalchemy@googlegroups.com 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 -~--~~~~--~~--~--~---
[sqlalchemy] Re: how to force a clean refresh of a lazy loaded attribute
On Feb 23, 2007, at 1:56 PM, Manlio Perillo wrote: Hi again. I have an object attribute loaded via lazy loader. This object is loaded in a transaction. Then, in another transaction, I ussue an update statement (via the sql module, not using the orm), that updates the table of the main object's attribute. The problem, now, is that I want to reload this attribute. I have tried, in a separate transaction: sess.update(obj) sess.expire(obj) One problem here is that the entire object is reloaded, and I do not want this. i think if you say delattr(obj, attributename), it will do a lazyload on the next run. The other problem (maybe a bug?) is that the orm issue another query to reload the data from the database, but in the object I still find the old values! I have submitted a ticket for the last problem (#492). refresh-expire cascade had not yet been implemented, just added it in the trunk. --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups sqlalchemy group. To post to this group, send email to sqlalchemy@googlegroups.com 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 -~--~~~~--~~--~--~---