PG client: errors are not getting propagated in transactions
See original GitHub issueVersion
4.1.0
Context
A query running without transaction throws a foreign key constraint violation error. While running the same query in a transaction - nothing happens, transaction is successfully committed.
Do you have a reproducer?
https://gist.github.com/ashertarno/d4672df84676168b82d8fa2f4abb2c6b
Steps to reproduce
- Create a table to work with and fill in a single row. Column parent is a foreign key to the column name:
create schema public; create table public.test (name varchar(50) primary key, parent varchar(50)); alter table public.test ADD CONSTRAINT the_parent_key FOREIGN KEY (parent) REFERENCES public.test(name) DEFERRABLE INITIALLY DEFERRED; insert into public.test (name, parent) values (‘adam’, null);
- The code in gist executes the following query:
insert into public.test (name, parent) values (‘john’, ‘mike’);
The query should fail because primary key ‘mike’ doesn’t exist in the name column;
- In the gist run the noTransaction(pool); method (make sure withTransaction() is commented). The query will throw an error as expected:
io.vertx.pgclient.PgException: { "message": "insert or update on table \"test\" violates foreign key constraint \"the_parent_key\"", "severity": "ERROR", "code": "23503", "detail": "Key (parent)=(mike) is not present in table \"test\".", "file": "ri_triggers.c", "line": "3266", "routine": "ri_ReportViolation", "schema": "public", "table": "test", "constraint": "the_parent_key" }
- Comment noTransaction(pool); method and uncomment withTransaction(pool). The same query will be executed in transaction, the transaction will be committed and no error will be thrown.
Extra
I tried to run the same tests with a query that throws “duplicate key value” error instead of foreign key constraint violation and it DOES work
“insert into public.test (name, parent) values (‘adam’, ‘mike’);”
io.vertx.pgclient.PgException: { "message": "duplicate key value violates unique constraint \"test_pkey\"", "severity": "ERROR", "code": "23505", "detail": "Key (name)=(adam) already exists.", "file": "nbtinsert.c", "line": "434", "routine": "_bt_check_unique", "schema": "public", "table": "test", "constraint": "test_pkey" }
I don’t know what is the difference in handling error 23503 vs 23505, but something is wrong here.
Environment
CentOS8 jdk11 PostgreSQL 10.7
Issue Analytics
- State:
- Created 2 years ago
- Comments:9 (5 by maintainers)
Top GitHub Comments
see https://github.com/eclipse-vertx/vertx-sql-client/issues/996
@vietj thanks, julien, as always - you rock.