Thanks a lot! This works well.

Tom

On Thu, 16 Jul 2015 at 21:23 Mike Bayer <mike...@zzzcomputing.com> wrote:

>
>
> On 7/16/15 2:28 PM, Tom Flannaghan wrote:
>
>  Thanks for your reply. Our exact problem is that we are creating empty
> detached objects from the primary key alone, and then merging them in to a
> session, so we can't do this:
>
> On Thursday, 16 July 2015 18:44:26 UTC+1, Michael Bayer wrote:
>>
>>
>> For now, I'd recommend either not using expire() or specifying specific
>> attribute names to expire().
>>
>>
>  I just included the expire() in the example as it was a more succinct
> way to reproduce the same bug.
>  Our code looks more like this:
>
>  detached_port = Port(name='test')
> make_transient_to_detached(detached_port)
> new_port = session.merge(detached_port, load=False)
> ...
>
>  In my example, Port only has two columns so this won't demonstrate the
> bug as the only non-deferred column is filled in already, but more
> complicated objects that are merged in this way will not defer columns. Do
> you think there a work around in this case?
>
> try this recipe which should reset the expired state of the target
> attributes individually:
>
>
> from sqlalchemy.orm import attributes
>
>
> def merge_load_false(session, obj):
>     obj = session.merge(obj, load=False)
>
>     obj_state = attributes.instance_state(obj)
>     obj_dict = obj_state.dict
>
>     deferred_keys = [
>         attr.key for attr in obj_state.mapper.column_attrs if
> attr.deferred]
>     for k in deferred_keys:
>         if k not in obj_dict:
>             obj_state._reset(obj_dict, k)
>     return obj
>
> a1 = merge_load_false(s, a1)
>
>
>
>
>
>
>  Thanks,
> Tom
>  --
>
> You received this message because you are subscribed to the Google Groups
> "sqlalchemy" group.
>
> To unsubscribe from this group and stop receiving emails from it, send an
> email to sqlalchemy+unsubscr...@googlegroups.com.
>
>
> To post to this group, send email to sqlalchemy@googlegroups.com.
> Visit this group at http://groups.google.com/group/sqlalchemy.
> For more options, visit https://groups.google.com/d/optout.
>
>  --
> You received this message because you are subscribed to a topic in the
> Google Groups "sqlalchemy" group.
> To unsubscribe from this topic, visit
> https://groups.google.com/d/topic/sqlalchemy/gRV7mSHFJiE/unsubscribe.
> To unsubscribe from this group and all its topics, send an email to
> sqlalchemy+unsubscr...@googlegroups.com.
> To post to this group, send email to sqlalchemy@googlegroups.com.
> Visit this group at http://groups.google.com/group/sqlalchemy.
> For more options, visit https://groups.google.com/d/optout.
>

-- 
You received this message because you are subscribed to the Google Groups 
"sqlalchemy" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to sqlalchemy+unsubscr...@googlegroups.com.
To post to this group, send email to sqlalchemy@googlegroups.com.
Visit this group at http://groups.google.com/group/sqlalchemy.
For more options, visit https://groups.google.com/d/optout.

Reply via email to