On 2 Nov., 19:09, Michael Bayer <[EMAIL PROTECTED]> wrote: > On Nov 2, 2007, at 1:15 PM, klaus wrote: > > > > > Thanks, but this doesn't seem to do what I wanted. The merge modifies > > the object and therefore tries to update the underlying table on > > session.flush(). So it might work if you prevented the save also. > > OK, ive committed the patch plus a fix + test for that specific > behavior to the trunk. If you try out the trunk, youll see that you > can merge(x, dont_load=True) and the objects get copied into the > session with the same "commited" state as the incoming object; so > that if no changes are present against the incoming object, no > changes will be tracked on the merged version either. >
Yep, this seems to do the trick. Nice work! > > I would prefer a solution, though, that allowed these objects to be > > immutable like their tables. That is, copy.copy could be used but no > > constructor and no setattr/delattr (and no remove). My implementation > > currently catches these with a NotImplementedError. > > "immutable" to me is a class behavior, so thats out of the SQLAlchemy > realm IMHO. the merge() with dont_load right now will copy the > committed state of the incoming object so it should act the same as > the cached object. copy.copy() is not smart enough here since it > cant detect child objects which are already present in the session > (which is the issue youre having). I agree, it is a class behavior, although one that I like very much. :-) Since the object has to be in the current session, which will reflect every change to the underlying read-only table, it is quite nice to catch programming errors on the first possible occasion. By the way, I still don't know what the child objects are in my setup. The tables that I would like to cache resemble enumeration types -- an id and a name, not much more, no references to other objects and no backrefs from those objects referencing them. They are simple and often used, seemingly ideal candidates for holding in memory. --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
