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.


> 
> 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 [email protected].
> To unsubscribe from this group, send email to 
> [email protected].
> 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 [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/sqlalchemy?hl=en.

Reply via email to