Skip to content
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

Return Problem if duplicate value contains ) #450

Closed
matthew-white opened this issue Feb 3, 2022 · 0 comments · Fixed by #471
Closed

Return Problem if duplicate value contains ) #450

matthew-white opened this issue Feb 3, 2022 · 0 comments · Fixed by #471
Labels

Comments

@matthew-white
Copy link
Member

Usually, if a database statement violates a uniqueness constraint, a 409.3 Problem is returned. However, if the duplicate value contains the character ), then a 500 error seems to be returned. This can be seen in this Sentry error. There, a form with a duplicate xmlFormId is uploaded, and the form ID contains ). I think the issue is that the ) causes the regular expression not to match:

} else if (error.code === '23505') { // unique_violation
const match = /^Key \(([^)]+)\)=\(([^)]+)\) already exists.$/.exec(error.detail);
if (match != null) {
const [ , rawFields, rawValues ] = match;
return reject(Problem.user.uniquenessViolation({
fields: splitPostgresTuple(rawFields).map(dequote),
values: splitPostgresTuple(rawValues),
table: error.table
}));
}
} else if (error.code === '23503') { // foreign_key_violation

The error message in this case looks like this:

Key ("projectId", "xmlFormId")=(3, my_form (1)) already exists.

The xmlFormId contains a space and parentheses, but the Postgres error message didn't enclose the value in quotes or escape those characters.

sadiqkhoja added a commit to sadiqkhoja/central-backend that referenced this issue Apr 11, 2022
@matthew-white matthew-white linked a pull request Apr 13, 2022 that will close this issue
matthew-white added a commit that referenced this issue Apr 13, 2022
…e_violation

bug #450: handle brackets in unique violation
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant