Objectstore saves dereferenced objects

Issue #128 resolved
Former user created an issue

Hello, I've just encountered a very odd behaviour of SA, revision 1190.

Basically, it seems to save dereferenced object as well, even though the object gets deleted from the current namespace. all the object values are actually kept and written to the database!

I don't have enoug SA knowledge to try to understand where the problem occurs; I guess it's got something to do with SA internal object-tracking (maybe it's employing a standard ref instead of a weakref somewhere).

demo attached.

Alan Franzoni <alan.franzoni at gmail dot com>

Comments (3)

  1. Mike Bayer repo owner

    the limitation on this is that the "new", "dirty", and "deleted" lists in the unit of work are not weak-referencing. creating a new object in memory that is mapped is the equivalent of saying "hey unit of work, new object for ya!".

    to help with this I have added a new method to objectstore/Session/unit of work called "expunge" that will force an object to be removed from the current unit of work:

       objectstore.expunge(obj1, obj2, ....)
    

    another solution would be to make the "new","dirty" HashSets "weak referencing". The challenge there is that the "new" list has to be an ordered set, since thats how the order is maintained when inserting rows from list-based attributes, which i think is important. If someone would like to contribute a weak-referencing ordered set object (i.e. the sqlalchemy.util.HashSet would get a "weak" flag that works with ordered=true), we can look into installing that instead.

    anyway i created a task #130 for that idea so marking this as a dupe of that.

  2. Former user Account Deleted

    I think that will be fine until the 'weak appraoch' is completed.

    I'm not on my main development computer now, but I think I can override the del method of my objects to call expunge() on the fly.

    Bye!

    Alan

  3. Former user Account Deleted

    of course the del override approach doesn't work because del is only called on true object deletion, this is always biting me, it's a big asymmetry to the whole Python architecture, BTW I'll manually create a deletion method.

  4. Log in to comment