Thanks, Michael!

That seems to have fixed it.

Cody

On Wed, Mar 23, 2011 at 1:41 PM, Michael Bayer <mike...@zzzcomputing.com> wrote:
>
> On Mar 23, 2011, at 11:28 AM, argentp...@gmail.com wrote:
>
>> Hello everyone,
>>
>> I am currently working on a Pylons project, and keep on receiving the
>> following error from SQLAlchemy:
>>
>> InvalidRequestError: stale association proxy, parent object has gone
>> out of scope
>
> this is because the parent is being garbage collected while the association 
> proxy is still doing its work:
>
> # will not work with immediate gc
> for item in session.query(Order).first().items:
>    print item
>
> the solution is to do it like this:
>
> o1 = session.query(Order).first()
> for item in o1.items:
>    print item
>
>
> example is attached.
>
>
>
>
>
>
>
>
>>
>> Here is the code for the model:
>>
>> class AccountInfo(Base):
>>    __tablename__ = 'account_info'
>>
>>    userid = schema.Column(types.Integer,
>>        schema.ForeignKey("users.id"), nullable=False, primary_key=True)
>>    enabled = schema.Column(types.Integer, default=1)
>>    username = schema.Column(types.Unicode(25), nullable=False,unique=True)
>>    password = schema.Column(types.Unicode(255), default=u'password')
>>    #leveled_privs = orm.relation("PrivilegeLevel",
>> backref="account_info",
>> collection_class=attribute_mapped_collection('priv_id'))
>>    # Below creates a relationship between AccountInfo and
>> PrivilegeLevel placed into a dict sorted by priv_id
>>    perms = orm.relation("Privilege", secondary=privileges_assoc)#,
>> backref="account_info")
>>    privileges = association_proxy("perms","name")
>>    def __init__(self,info):
>>        for k,v in info:
>>            setattr(self, k, v)
>>
>> "privileges" is the source of the problem. Whenever I try to use it in
>> the site, I get the previously mentioned error. I've taken a look at
>> the documentation on the site, and I believe that I am using it
>> correctly.
>>
>> When I searched google, I wasn't able to find anything useful. I did
>> find something about removing stale cached attribute instances here:
>> http://www.mail-archive.com/sqlalchemy@googlegroups.com/msg08914.html
>>
>> But I couldn't find any attributes on my instances that seemed similar
>> to what that user was speaking about.
>>
>> Here's an example of how I'm using it, if that helps:
>>
>>> "edit.perms" in myAccountInfoInstance.privileges
>> True
>>
>> In the Python shell, it works occasionally. In a request, not at all
>>
>> Is anyone able to help me?
>>
>> Cody
>>
>> --
>> 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 
>> sqlalchemy+unsubscr...@googlegroups.com.
>> 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 sqlalchemy@googlegroups.com.
> To unsubscribe from this group, send email to 
> sqlalchemy+unsubscr...@googlegroups.com.
> For more options, visit this group at 
> http://groups.google.com/group/sqlalchemy?hl=en.
>
>
>



-- 
    .-.
    /v\    L   I   N   U   X
   // \\  >Phear the Penguin<
  /(   )\
   ^^-^^

-- 
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 
sqlalchemy+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/sqlalchemy?hl=en.

Reply via email to