question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

PG client: errors are not getting propagated in transactions

See original GitHub issue

Version

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

  1. 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);

  1. 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;

  1. 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" }

  1. 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:closed
  • Created 2 years ago
  • Comments:9 (5 by maintainers)

github_iconTop GitHub Comments

0reactions
ashertarnocommented, Jun 23, 2021

@vietj thanks, julien, as always - you rock.

Read more comments on GitHub >

github_iconTop Results From Across the Web

nodejs pg transactions without nesting - Stack Overflow
The scenario I am looking at is where an array has a series of values that I wish to insert into a table,...
Read more >
Database Engine events and errors - SQL Server
Consult this MSSQL error code list to find explanations for error messages for SQL Server database engine events.
Read more >
pg.Client - node-postgres
When the client is in the process of connecting, dispatching a query, or disconnecting it will catch and foward errors from the PostgreSQL...
Read more >
Troubleshoot | Cloud SQL for PostgreSQL
No response to TCP keep-alive commands (either the client or the server isn't responsive, possibly overloaded); The database engine connection lifetime was ...
Read more >
Handling Errors | Couchbase Docs
If you get a RequestCanceledException , it means the SDK is not able to further retry the operation and it is terminated before...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found