mviamari wrote:
>
> Hello,
>
> I'm writing tests for my database, and I've run into a little bit of
> confusion.
>
> Say I have a class (we'll call it person) with two declared attributes
> that correspond to db columns:
>
> person.id
> person.name
>
> If I randomly assign a person object another attribute dynamically:
>
> person.undeclared_value = 'New'
>
> That value doesn't get stored in the database.  (That part I expected
> and understand).
> What I don't understand is if I commit the object, set it to None (to
> presumably garbage collect it) and then reacquire it from the DB,
> sometimes that dynamically declared attribute is still pesent:
>
> person = Person()
> person.name = 'John Smith'
> person.new_attr = 'New'
>
> commit()
> id = person.id #id isn't assigned till after a commit
>
> person = None
> person = Person.get_by(id=id)
>
> #This is expected to be true
> assert person.name = 'John Smith'
>
> #This is expected to yield an AttributeError, but sometimes it doesn't
> assert person.new_attr = 'New'
>
> Based on my tests, it appears that the sometimes it doesn't is
> whenever there are relationships created in the session.  If I only
> create one object and follow the above pattern, I get the expected
> results.  If I create two objects and the relationship between them,
> then I get the unexpected results.
>
> Does anyone have any idea what might be going on? I think the object
> is getting stored in the session, and when I reobtain the object it
> just uses the reference in the session.

this is the identity map at work.  Read "Is the session a cache?" at
http://www.sqlalchemy.org/docs/05/session.html#frequently-asked-questions
.


--~--~---------~--~----~------------~-------~--~----~
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