-
-
Notifications
You must be signed in to change notification settings - Fork 1.5k
'on conflict ... do update ...' where clause and implicit returning #3813
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
Michael Bayer (@zzzeek) wrote: and if so, please produce the SQL being emitted. Also note that the "implicit_returning" flags that are accessible via the API in create_engine() and Table should likely not be used, as the upsert feature is tested only against the default RETURNING behavior. |
Pawel (@pszynk) wrote: Yeah I though that #3807 could resolve this (I was the one that asked for help on google groups), but I can confirm that this problem still exists, I tested it on master. As you said, turning the flag I think I found out how to recreate this error. The key is not to put primary key into VALUES so the INSERT (with I wrote this test to replicate it: (in
and here is the SQL:
|
Pawel (@pszynk) wrote: ofc this assertion is wrong, just wanted to check for the exception. Proper test would be
|
Michael Bayer (@zzzeek) wrote: perfect, thanks very much! |
Michael Bayer (@zzzeek) wrote: so here is your workaround:
which is the same thing that insert from select does. |
Michael Bayer (@zzzeek) wrote: Check row for None with implicit returning PK to accommodate ON CONFLICT An adjustment to ON CONFLICT such that the "inserted_primary_key" Change-Id: I0794e95c3ca262cb1ab2387167d96b8984225fce → 20384e8 |
Changes by Michael Bayer (@zzzeek):
|
Migrated issue, originally created by Pawel (@pszynk)
When using Postgres 9.5 INSERT ... ON CONFLICT ... DO UPDATE ... I get an error:
I have hard time recreating issue with test (sorry I'm a bit new to the project), but i think I know what conditions cause this error.
True
so sth like this should give an error:
This test passes but
_implicit_returning
here isFalse
. In my code I use session andimplicit_returning
isTrue
(is it because of session?)Then in file:
sqlalchemy/engine/default.py:862
function:_setup_crud_result_proxy
we go inside both
if
's androw = result.fetchone()
sets row toNone
because of thewhere
clause I think (nothing will be inserted or updated). Then the callself._setup_ins_pk_from_implicit_returning(row)
withrow == None
give an error.The text was updated successfully, but these errors were encountered: