Oh, it seems that merge() actually does populate the b_id if that B is
non-conflicting... Seems I have another problem .
Thank you anyway, Michael
вторник, 14 апреля 2015 г., 20:08:04 UTC+5 пользователь Michael Bayer
написал:
>
>
>
> that's not what I see happening here. I see very simply that the B.id_
> column is a SERIAL so is linked to a sequence, however you are inserting a
> row with a hardcoded "1" for a primary key; so the second B object, which
> relies on the sequence, fails due to an identity conflict.
>
> So let's repair the test case first, and that first B.id we'll set to "10"
> so that it doesn't conflict.
>
> Now we get the error you probably intended to send:
>
> SELECT "Rel".id_a AS "Rel_id_a", "Rel".id_b AS "Rel_id_b", "Rel".rel_data
> AS "Rel_rel_data"
> FROM "Rel"
> WHERE "Rel".id_a = %(param_1)s AND "Rel".id_b = %(param_2)s
> 2015-04-14 11:05:11,850 INFO sqlalchemy.engine.base.Engine {'param_1':
> 800, 'param_2': symbol('NEVER_SET')}
>
> where this is, the merge() is proceeding to attempt to locate the object
> by primary key but the PK is not filled in. This is the expected
> behavior. The primary key of an object is never auto-populated until it
> is flushed. So here, if you are passing in a transient object, you need
> to set the PK yourself:
>
> second_b = B(data='foooo')
> session.add(second_b)
> session.flush()
> x = session.merge(Rel(id_a=800, rel_data="second", id_b=second_b.id_))
>
>
>
>
--
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 [email protected].
To post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/sqlalchemy.
For more options, visit https://groups.google.com/d/optout.