Re: [sqlalchemy] creating objects in merge() does not set primary key

2018-01-02 Thread Mike Bayer
On Tue, Jan 2, 2018 at 12:06 PM, Tim Chen wrote: > Ah yes, makes sense. So there is a slight difference in that add() will > modify the original object, while merge() will not. Thanks for the > explanation! > > It would be great if this difference could be added to the docs

Re: [sqlalchemy] creating objects in merge() does not set primary key

2018-01-02 Thread Tim Chen
Ah yes, makes sense. So there is a slight difference in that add() will modify the original object, while merge() will not. Thanks for the explanation! It would be great if this difference could be added to the docs here

Re: [sqlalchemy] creating objects in merge() does not set primary key

2018-01-02 Thread Mike Bayer
On Tue, Jan 2, 2018 at 11:44 AM, Tim Chen wrote: > Hrmm, that's not what I'm getting. Maybe I'm misunderstanding something - > here's a simple test to illustrate my example. test_add() works as > expected, test_merge() fails. > > > import sqlalchemy as sa > from

Re: [sqlalchemy] creating objects in merge() does not set primary key

2018-01-02 Thread Tim Chen
Hrmm, that's not what I'm getting. Maybe I'm misunderstanding something - here's a simple test to illustrate my example. test_add() works as expected, test_merge() fails. import sqlalchemy as sa from sqlalchemy.orm import sessionmaker from sqlalchemy.ext.declarative import declarative_base

Re: [sqlalchemy] creating objects in merge() does not set primary key

2018-01-01 Thread Mike Bayer
On Mon, Jan 1, 2018 at 9:18 PM, Tim Chen wrote: > When I merge() an object without a PK, I expect similar behavior to add(), > in that the autogenerated PK is returned and set on the object. Is that not > expected behavior? it is, assuming the Session has flushed. > > -- >

[sqlalchemy] creating objects in merge() does not set primary key

2018-01-01 Thread Tim Chen
When I merge() an object without a PK, I expect similar behavior to add(), in that the autogenerated PK is returned and set on the object. Is that not expected behavior? -- SQLAlchemy - The Python SQL Toolkit and Object Relational Mapper http://www.sqlalchemy.org/ To post example code,