diff options
| author | mike bayer <mike_mp@zzzcomputing.com> | 2022-01-22 14:32:52 +0000 |
|---|---|---|
| committer | Gerrit Code Review <gerrit@ci3.zzzcomputing.com> | 2022-01-22 14:32:52 +0000 |
| commit | f8fd9c64d6967b60f4fbf568465af9f0d0c0f482 (patch) | |
| tree | 93ad8a4c4edd3538c62e5eaa8cae8b2dfd8a757e /lib/sqlalchemy | |
| parent | fd4ab9bbe19bb79d91a66f1458848fbe7d65b144 (diff) | |
| parent | 8a1931601d3b105ad585ef39840c8251ebdb44a2 (diff) | |
| download | sqlalchemy-f8fd9c64d6967b60f4fbf568465af9f0d0c0f482.tar.gz | |
Merge "Skip PK returned as None for RETURNING, server side default" into main
Diffstat (limited to 'lib/sqlalchemy')
| -rw-r--r-- | lib/sqlalchemy/orm/persistence.py | 25 |
1 files changed, 25 insertions, 0 deletions
diff --git a/lib/sqlalchemy/orm/persistence.py b/lib/sqlalchemy/orm/persistence.py index 6696b34d5..b3381b039 100644 --- a/lib/sqlalchemy/orm/persistence.py +++ b/lib/sqlalchemy/orm/persistence.py @@ -1177,6 +1177,22 @@ def _emit_insert_statements( c.inserted_primary_key_rows, c.returned_defaults_rows or (), ): + if inserted_primary_key is None: + # this is a real problem and means that we didn't + # get back as many PK rows. we can't continue + # since this indicates PK rows were missing, which + # means we likely mis-populated records starting + # at that point with incorrectly matched PK + # values. + raise orm_exc.FlushError( + "Multi-row INSERT statement for %s did not " + "produce " + "the correct number of INSERTed rows for " + "RETURNING. Ensure there are no triggers or " + "special driver issues preventing INSERT from " + "functioning properly." % mapper_rec + ) + for pk, col in zip( inserted_primary_key, mapper._pks_by_table[table], @@ -1225,6 +1241,15 @@ def _emit_insert_statements( ) primary_key = result.inserted_primary_key + if primary_key is None: + raise orm_exc.FlushError( + "Single-row INSERT statement for %s " + "did not produce a " + "new primary key result " + "being invoked. Ensure there are no triggers or " + "special driver issues preventing INSERT from " + "functioning properly." % (mapper_rec,) + ) for pk, col in zip( primary_key, mapper._pks_by_table[table] ): |
