On Feb 23, 2010, at 7:28 AM, Kent wrote:

> Thanks, and I knew I had brought up similar behavior before, but it
> was in the context of merge() by itself (with composite primary
> keys).  Before I was wondering why merge expires columns that merge()
> originally fetched.  This seemed like a different issue to me on the
> surface, because in this case, I *already* have the persistent
> instance in the session *before* calling merge, and merge expired it
> anyway.
> 
> Thanks for your help.

that ticket has been committed so if you try out 0.6 trunk it should not be 
reloading already loaded attributes.



> 
> 
> On Feb 21, 2:09 pm, Michael Bayer <mike...@zzzcomputing.com> wrote:
>> On Feb 21, 2010, at 2:03 PM, Michael Bayer wrote:
>> 
>> 
>> 
>> 
>> 
>>> On Feb 21, 2010, at 1:51 PM, Michael Bayer wrote:
>> 
>>>> On Feb 20, 2010, at 5:12 PM, Kent wrote:
>> 
>>>>> If I have a persistent instance in my session and I call merge on an
>>>>> object that equates to that instance, some attributes (it seems those
>>>>> that aren't explicitly set on the merging instance) are expired and
>>>>> get re-queried the next time they are referenced.
>> 
>>>>> We will be supporting remote databases and I may be iterating at some
>>>>> points over hundreds or more records that I've already queried and are
>>>>> persistent, so I wish these wouldn't expire.
>> 
>>>>> Is this behavior intentional?
>> 
>>>> I think we already mentioned this in a previous email.  yes, that is the 
>>>> current behavior and is intentional.   If you'd like these to be merged in 
>>>> as None, set them to None on your incoming instance.  Otherwise their 
>>>> value is undefined and it is the correct behavior for them to be fetched 
>>>> from the database when requested.
>> 
>>> I think we also mentioned that i was going to investigate limiting this 
>>> behavior to the load=False condition.  that issue still remains as the 
>>> single test we have which fails upon changing the behavior uses load=False.
>> 
>> yes, its ticket #1681.  the issue has already been logged and here is the 
>> message where I mentioned as much:  
>> http://groups.google.com/group/sqlalchemy/msg/6057ea3a24a548e9?
>> 
>> 
>> 
>>>>> Version 0.5.8
>> 
>>>>> For example, see the output from this simple script:
>> 
>>>>> =================================
>> 
>>>>> from sqlalchemy import *
>>>>> from sqlalchemy.orm import *
>> 
>>>>> engine = create_engine('postgres://kb:k...@localhost:5444/kb',echo=True)
>>>>> metadata = MetaData()
>>>>> Session = sessionmaker(bind=engine)
>>>>> DBSession = Session()
>> 
>>>>> order_table = Table("orders", metadata,
>>>>>  Column("orderid", Unicode, primary_key=True),
>>>>>  Column("type", Unicode)
>>>>> )
>> 
>>>>> class Order(object):
>>>>>  pass
>> 
>>>>> order_mapper = mapper(Order, order_table)
>> 
>>>>> #metadata.create_all(engine)
>> 
>>>>> o=Order()
>>>>> o.orderid=u'SALE25863'
>> 
>>>>> DBSession.query(Order).get(u'SALE25863')
>> 
>>>>> merged=DBSession.merge(o)
>> 
>>>>> merged.orderid
>>>>> merged.type    #<------------At this point, type is expired
>>>>> ################
>> 
>>>>> ==================================================
>> 
>>>>> output:
>>>>> ==================================================
>>>>>>>> from sqlalchemy.orm import *
>> 
>>>>>>>> engine = 
>>>>>>>> create_engine('postgres://kb:k...@localhost:5444/kb',echo=True)
>>>>>>>> metadata = MetaData()
>>>>>>>> Session = sessionmaker(bind=engine)
>>>>>>>> DBSession = Session()
>> 
>>>>>>>> order_table = Table("orders", metadata,
>>>>> ...     Column("orderid", Unicode, primary_key=True),
>>>>> ...     Column("type", Unicode)
>>>>> ... )
>> 
>>>>>>>> class Order(object):
>>>>> ...     pass
>>>>> ...
>>>>>>>> order_mapper = mapper(Order, order_table)
>> 
>>>>>>>> #metadata.create_all(engine)
>>>>> ...
>>>>>>>> o=Order()
>>>>>>>> o.orderid=u'SALE25863'
>> 
>>>>>>>> DBSession.query(Order).get(u'SALE25863')
>>>>> 2010-02-20 05:55:11,859 INFO sqlalchemy.engine.base.Engine.0x...2cd0
>>>>> BEGIN
>>>>> 2010-02-20 05:55:11,863 INFO sqlalchemy.engine.base.Engine.0x...2cd0
>>>>> SELECT orders.orderid AS orders_orderid, orders.type AS orders_type
>>>>> FROM orders
>>>>> WHERE orders.orderid = %(param_1)s
>>>>> 2010-02-20 05:55:11,864 INFO sqlalchemy.engine.base.Engine.0x...2cd0
>>>>> {'param_1': 'SALE25863'}
>>>>> <__main__.Order object at 0x14ee710>
>> 
>>>>>>>> merged=DBSession.merge(o)
>> 
>>>>>>>> merged.orderid
>>>>> u'SALE25863'
>> 
>>>>> #################################
>>>>>>>> merged.type   #<------------At this point, type is expired 
>>>>>>>> ################
>>>>> 2010-02-20 05:55:11,870 INFO sqlalchemy.engine.base.Engine.0x...2cd0
>>>>> SELECT orders.type AS orders_type
>>>>> FROM orders
>>>>> WHERE orders.orderid = %(param_1)s
>>>>> 2010-02-20 05:55:11,870 INFO sqlalchemy.engine.base.Engine.0x...2cd0
>>>>> {'param_1': 'SALE25863'}
>>>>> u'SAL'
>> 
>>>>> --
>>>>> You received this message because you are subscribed to the Google Groups 
>>>>> "sqlalchemy" group.
>>>>> To post to this group, send email to sqlalch...@googlegroups.com.
>>>>> To unsubscribe from this group, send email to 
>>>>> sqlalchemy+unsubscr...@googlegroups.com.
>>>>> For more options, visit this group 
>>>>> athttp://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 sqlalch...@googlegroups.com.
>>>> To unsubscribe from this group, send email to 
>>>> sqlalchemy+unsubscr...@googlegroups.com.
>>>> For more options, visit this group 
>>>> athttp://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 sqlalch...@googlegroups.com.
>>> To unsubscribe from this group, send email to 
>>> sqlalchemy+unsubscr...@googlegroups.com.
>>> For more options, visit this group 
>>> athttp://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 sqlalch...@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 sqlalch...@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