Skip to content

UUIDField not being validated for retrieval #5197

@diogobaeder

Description

@diogobaeder

Checklist

  • I have verified that that issue exists against the master branch of Django REST framework.
  • I have searched for similar issues in both open and closed tickets and cannot find a duplicate.
  • This is not a usage question. (Those should be directed to the discussion group instead.)
  • This cannot be dealt with as a third party library. (We prefer new functionality to be in the form of third party libraries where possible.)
  • I have reduced the issue to the simplest possible case.
  • I have included a failing test as a pull request. (If you are unable to do so we can still accept the issue.)

Steps to reproduce

Hi,

I'm a newcomer to DRF, and an issue I'm having is that I'm using Django's UUIDField in some models and using them as the lookup_fields in my serializers. They work fine when I send a request with a correctly-formatted UUID, but DRF simply fails with a server error if the request sends an invalid string (such as "invalid") - instead of responding with HTTP 400 or 404, which was what I would expect. I tried debugging the code a bit, and it doesn't seem to be validated anywhere when calling retrieve() from the RetrieveModelMixin. Then I receive a django.core.exceptions.ValidationError which is bubbled up until the application layer, instead of being handled by DRF gracefully, since it's a case of user error and not application error.

I believe this is a bug, but, if it's not and if it's up to the developers to code the validation themselves, please let me know.

So the steps to reproduce are pretty simple:

  1. Add a UUIDField to a model
  2. Define a serializer for this model
  3. Define the uuid field as the lookup field
  4. Send a test request to the detail view but passing "invalid" as the uuid

Expected behavior

Either an HTTP 400 or 404 response

Actual behavior

The application fails and lets the low-level validation error bubble up, responding with an HTTP 500 response to the client

Metadata

Metadata

Assignees

No one assigned

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions