-
Notifications
You must be signed in to change notification settings - Fork 3.8k
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
Add constraint name to foreign key/check constraint errors #36494
Comments
Thanks for the report. So, to be clear, Ecto uses the Does Ecto also parse the error message itself? |
That is correct. Ecto first attempts to grab the constraint name out of the ErrorResponse's To support Ecto, all we really need is the |
Also, if you'd really like to see what Ecto is doing, here's where Ecto does its pattern matching on the error responses: https://github.com/elixir-ecto/ecto_sql/blob/1a6c92a001912fe3df7046fc09dbb1611241b548/lib/ecto/adapters/postgres/connection.ex#L18-L58. The first 4 function heads are where it matches on the constraint field and the next 4 function heads are where they fall back to parsing the error message. |
@RaduBerinde is this done, or easier now? |
I was not aware of this, I'll do some research. |
My understanding of the work to do here is like this:
The tricky bit is that we (usually) forget about the names when we do physical planning. But that's where Radu has an edge. |
Thanks, makes sense. I guess I would add something similar to |
This change adds infrastructure to set the "constraint name" field of errors on pgwire and uses it to populate the constraint name for foreign key violation errors. Fixes cockroachdb#36494. Release note (sql change): foreign key violation errors now fill in the "constraint name" error message field.
This change adds infrastructure to set the "constraint name" field of errors on pgwire and uses it to populate the constraint name for foreign key violation errors. Fixes cockroachdb#36494. Release note (sql change): foreign key violation errors now fill in the "constraint name" error message field.
This change adds infrastructure to set the "constraint name" field of errors on pgwire and uses it to populate the constraint name for foreign key violation errors. Fixes cockroachdb#36494. Release note (sql change): foreign key violation errors now fill in the "constraint name" error message field.
54313: sql: set constraint name in pg error for FK violations r=RaduBerinde a=RaduBerinde This change adds infrastructure to set the "constraint name" field of errors on pgwire and uses it to populate the constraint name for foreign key violation errors. Fixes #36494. Release note (sql change): foreign key violation errors now fill in the "constraint name" error message field. 54542: sql: enable partial inverted indexes in randomized tests r=rytaft a=mgartner Now that partial inverted indexes can be created, they can be generated in randomized tests. Release note: None Co-authored-by: Radu Berinde <[email protected]> Co-authored-by: Marcus Gartner <[email protected]>
This change adds infrastructure to set the "constraint name" field of errors on pgwire and uses it to populate the constraint name for foreign key violation errors. Fixes cockroachdb#36494. Release note (sql change): foreign key violation errors now fill in the "constraint name" error message field.
Is your feature request related to a problem? Please describe.
I'm running into an issue where Ecto isn't able to nicely handle cockroach's constraint errors (
foreign_key_violation
,unique_violation
,exclusion_violation
andcheck_violation
) because cockroach's constraint errors do not include aconstraint_name
error field as part of the error response. This behavior was added in postgres 9.3 under a feature titled "Provide clients with constraint violation details as separate fields".Describe the solution you'd like
It would be great if cockroach could add the failing constraint name to these errors, so they can be used by higher level application code. The field id should be
n
as described in 53.8. Error and Notice Message Fields of the postgres docs. This field is also know asPG_DIAG_CONSTRAINT_NAME
in thePQresultErrorField
docs.It would also be nice if the error message text could match that of postgres, but I understand if there's reasons that it's been changed.
Additional context
Here are the differences between the postgres and cockroach foreign key error responses, as parsed by postgrex.
Here are the differences in the error messages between cockroach and postgres:
insert or update on table "users" violates foreign key constraint "users_account_id_fkey"
foreign key violation: value ['k'] not found in accounts@primary [id] (txn=8c87c634-cf34-4e69-8bf3-ea6758e65a82)
Issue tracking ecto compatibility: #33441
Psycopg2 issue where they were working to support additional
PG_DIAG_*_NAME
fields likePG_DIAG_CONSTRAINT_NAME
: psycopg/psycopg2#149The text was updated successfully, but these errors were encountered: