-
Notifications
You must be signed in to change notification settings - Fork 31
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
validate uuid id/pk #1514
base: main
Are you sure you want to change the base?
validate uuid id/pk #1514
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the PR, @akihikokuroda . You don't need to validate perse the UUID format. This is something that django is doing in its ORM. The problem is that we are not capturing the exception for that. The idea is to add a try/except
in the queries where we are using the UUID.
These changes check the uuid before django validates it. So it stops raising exceptions and returns 404 for the requests. |
I know, I know. But we can rely on Django validation perfectly, we just need to capture the exception that it raises. We don't need to create our own validator for that. |
I believe that the django validation happens when it saves to or retrieves from the database. It's much cleaner and safer if we validate it at the entry of the apis. |
My proposal @akihikokuroda :
|
Are the queries database query? Where do you propose to put the The UUID utility seems for generating an UUID. I don't see the method for validating it. |
It happens in every You just need to encapsulate that call in a
If you try to create an UUID with a value that is not a valid UUID it will raise an exception that you can capture similar to what you were doing with the pattern. If you see that that logic doesn't fit correctly I'm fine looking for alternatives @akihikokuroda like what you did with the pattern, but let's try something that it just exists first. |
Summary
Validate UUID used as the id/pk for the model instance
Details and comments