-
Notifications
You must be signed in to change notification settings - Fork 713
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
Adds error handling for badly formed UUIDs sent to API endpoints #11009
Adds error handling for badly formed UUIDs sent to API endpoints #11009
Conversation
…s for badly formed UUIDs.
Build Artifacts
|
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.
Code is fine, some parts not easy to understand for me as they're clearly a special and smart use of the Django features. Added tests are pretty clear though.
I see no problems in the code and everything went well in my tests. I haven't tested in Postgresql where UUID format is a bit different but I trust Django folks have kept that in mind.
# maps to this filter when using the UUIDField in a filter. | ||
from morango.models import UUIDField | ||
|
||
FilterSet.FILTER_DEFAULTS.update({UUIDField: {"filter_class": UUIDFilter}}) |
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.
I didn't know about the existence of FILTER_DEFAULTS
nor I could find it in the documentation https://django-filter.readthedocs.io/
I only have found some references in the django-filter forums to underestand how it worked. Looking at the code makes sense, and also, if I understand it correctly the place in the code where you added it forces it to be active during the execution of the whole django request. is that interpretation correct?
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.
Yes - it does not appear to be documented, which is unfortunate, but it seemed to be the only way to set this global mapping from Field type to Filter class.
The other alternative would be to subclass FilterSet and then systematically use that for all our FilterSets (although, this would not work for automatically generated FilterSets using DRF's magic: https://www.django-rest-framework.org/api-guide/filtering/#djangofilterbackend as there doesn't seem to be a setting to set the default FilterSet class).
Setting it here seems to be early enough in the Django initialization sequence that it is now set for any derived class - because of the import path from morango, it needs to happen after Django app initialization, because of access to the models module.
Summary
References
Fixes #10999 - actual Sentry reports includes multiple endpoints, all of which should be addressed here (some of which are addressed by previous work).
Reviewer guidance
Where needed I have added additional test coverage, but most of this is just defensive programming.
Testing checklist
PR process
Reviewer checklist
yarn
andpip
)