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

bug: all IntegrityErrors are reported as unique constraint violations during model creation/update #637

Open
shrouxm opened this issue Jul 6, 2023 · 0 comments
Labels

Comments

@shrouxm
Copy link
Member

shrouxm commented Jul 6, 2023

Description

Currently any integrity error that occurs when trying to save a model to the database is reported as a unique constraint violation, when it could be for other reasons (one I have encountered is supplying NULL to a non-nullable field). Relevant code here:

try:
model_instance.save()
except IntegrityError as exc:
logger.info(
"Attempt to mutate an model, but it's not unique",
extra={"model": cls.model_class.__name__, "integrity_error": exc},
)
# It's not trivial identify the exact field(s) that originated the integrity errror
# here, so we identify the error as NON_FIELD_ERROR with the unique code.
validation_error = ValidationError(
message={
NON_FIELD_ERRORS: ValidationError(
message=f"This {cls.model_class.__name__} already exists",
code="unique",
)
},
)
raise GraphQLValidationException.from_validation_error(
validation_error, model_name=cls.model_class.__name__
)

Expected behavior

Integrity errors report the actual error which occurred.

Actual behavior

We always report a unique constraint violation.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
Status: Todo
Development

No branches or pull requests

1 participant