Re: [sqlalchemy] How to use make_transient() to duplicate an SQLAlchemy mapped object?

2015-05-23 Thread Mike Bayer



On 5/23/15 11:52 AM, c.bu...@posteo.jp wrote:

Hi Mike,

thanks for your help.

On 2015-05-22 02:32 Mike Bayer  wrote:

if you copy an object to transient, now instance_state.key is gone,
next step is erase the primary key column-holding attributes, such as
myobject.id = None.   object on flush will have no PK value and
autoincrement will be used instead.

This works for the case.

But I wonder...
When I create a really new object, add() it to the session, I don't have
to call flush() on the session before commit() it.

The add-and-commit-part of my application doesn't know where the object
comes from. It doesn't know if it is real new or if it is a "duplicate"
created with make_transient() and Primary_Key=None.

See what I mean?


not really.   The object is "really new", or it is "make_transient w/ 
None primary key".   Both will get flushed when you say 
Session.commit().  I have no idea what you're trying to do.


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


Re: [sqlalchemy] How to use make_transient() to duplicate an SQLAlchemy mapped object?

2015-05-23 Thread c.buhtz
Hi Mike,

thanks for your help.

On 2015-05-22 02:32 Mike Bayer  wrote:
> if you copy an object to transient, now instance_state.key is gone,
> next step is erase the primary key column-holding attributes, such as 
> myobject.id = None.   object on flush will have no PK value and 
> autoincrement will be used instead.

This works for the case.

But I wonder...
When I create a really new object, add() it to the session, I don't have
to call flush() on the session before commit() it.

The add-and-commit-part of my application doesn't know where the object
comes from. It doesn't know if it is real new or if it is a "duplicate"
created with make_transient() and Primary_Key=None.

See what I mean?

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


Re: [sqlalchemy] How to use make_transient() to duplicate an SQLAlchemy mapped object?

2015-05-21 Thread Mike Bayer



On 5/22/15 1:10 AM, c.bu...@posteo.jp wrote:

I opened a questions with example (pseudo) code on stackoverflow for
that.


I know the question how to duplicate or copy a SQLAlchemy mapped object
was asked a lot of times. The answer always depends on the needs or how
"duplicate" or "copy" is interpreted. This is a specialized version of
the question because I got the tip to use make_transient() for that.

But I have some problems with that. I don't really know how to handle
the primary key (PK) here. In my use cases the PK is always
autogenerated by SQLA (or the DB in background). But this doesn't
happen with a new duplicated object.
if you copy an object to transient, now instance_state.key is gone, next 
step is erase the primary key column-holding attributes, such as 
myobject.id = None.   object on flush will have no PK value and 
autoincrement will be used instead.









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


[sqlalchemy] How to use make_transient() to duplicate an SQLAlchemy mapped object?

2015-05-21 Thread c.buhtz
I opened a questions with example (pseudo) code on stackoverflow for
that.


I know the question how to duplicate or copy a SQLAlchemy mapped object
was asked a lot of times. The answer always depends on the needs or how
"duplicate" or "copy" is interpreted. This is a specialized version of
the question because I got the tip to use make_transient() for that.

But I have some problems with that. I don't really know how to handle
the primary key (PK) here. In my use cases the PK is always
autogenerated by SQLA (or the DB in background). But this doesn't
happen with a new duplicated object.

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