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
PostgreSQL throws DataError when trying to retrieve objects with invalid UUID #46
Comments
I think raising a ValueError (as in #48) is the correct behavior, not returning an arbitrary valid UUID that matches nothing in the database. If you are using the UUID in the URL, you could set the regex to allow only UUIDs with correct length. This will raise |
One more thing to check: hon-hex characters in the string. UUIDs with correct lenght containing characters g-z will still cause a 500 error. Solution for the url:
|
@ksonbol You are right -- raising ValueError is supported by Django to return 404 response during lookup, which means special URL match is not needed. Django doc |
The following code will trigger the problem with PostgreSQL backend:
An example traceback:
PostgreSQL has a UUID type and throws an error with badly formatted UUID. However, it is not the expected behavior of an API. When user provides an invalid UUID, the API in most cases is expected to return 404, instead of 500 caused by this uncaught exception.
The problem lies in method
get_db_prep_value
. If the provided UUID is not valid, the method should return an arbitrary valid UUID that matches nothing in the database.The text was updated successfully, but these errors were encountered: