Weird problem in method expire_attrbutes in class InstanceState

Issue #1225 resolved
Former user created an issue

I have some code which did run with Sqlalchemy RC2 but not with RC3.

The problem is that my code aborts when I try to commit data to the SQLite database with the following exception:

The exception occurs in method expire_attributes in class InstanceState in module orm.attributes.

I tried some debugging and found the following.

The exception occurs at this line in the mentioned method:

    {{{ self.dict.pop(key, None) }}}

The exception is thrown because self.dict is None. I placed some print statements around that statement:
{{{
    print self.dict is None
    self.dict.pop(key, None)
    print self.dict is None

and found out that self.dict became None after executing the pop statement! At the next iteration of the containing loop the exception was therefore thrown.

This is somewhat puzzling for me, since self.dict is a simple dictionary and I can not understand how a pop call could make this happen.

I tried single stepping at this line and found out that the debugger suddenly placed me into the method sqlalchemy/orm/identity.py(220)_cleanup(). How this happened I did not understand at that moment so I decided to stop stepping the code.

I tried something else: I assigned a variable the reference to self.dict and changed the code to use the variable to pop from:

The code:

        for key in attribute_names:
            self.dict.pop(key, None)
            ...

became

        d = self.dict
        for key in attribute_names:
            d.pop(key, None)
            ...

This made the code run without throwing the TypeError Exception. However, I can not say if this is the right thing to do.

This is all information I have about this problem.

Unfortunately I cannot provide a test case because I do not know where to begin creating one.

Comments (2)

  1. Mike Bayer repo owner

    the behavior you're seeing is related to the InstanceState's reaction to garbage collection. The issue has been fixed in the latest trunk and rc4 will be forthcoming.

  2. Log in to comment