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

ValidationError when using fastuuid with django's UUID field #14

Open
LegNeato opened this issue Feb 17, 2021 · 5 comments
Open

ValidationError when using fastuuid with django's UUID field #14

LegNeato opened this issue Feb 17, 2021 · 5 comments

Comments

@LegNeato
Copy link

Doing a simple

-from uuid import uuid4
+from fastuuid import uuid4

On a django field:

    id = models.UUIDField(primary_key=True, default=uuid4)

Gives me errors like the following:

django.core.exceptions.ValidationError: ['“eb457f28-7cdc-4068-894b-1d0adfeb3e8d” is not a valid UUID.']
@thedrow
Copy link
Collaborator

thedrow commented Feb 18, 2021

Hi.
This was never tested before so thank you for trying!

We'll either need a custom field or fix the code upstream.
Django checks that the object you are providing is the regular uuid.UUID object from the standard library and if it isn't it attempts to cast it and fails.

See here.

All you need to do is to override to_python to check against fastuuid's UUID type.

Another workaround is to make isinstance(value, uuid.UUID) pass the test as they have exactly the same interface.

@LegNeato
Copy link
Author

Great, I'll try to get time to put up a PR in the next week or so, thanks for looking so quickly!

@ollz272
Copy link

ollz272 commented Apr 17, 2023

This similarly happens with SQLAlchemys Uuid column, which is stopping us from adopting this package

@LegNeato
Copy link
Author

I no longer need this, hence no PR...but the offending django code has moved to https://github.com/django/django/blob/594fcc2b7427f7baf2cf1a2d7cd2be61467df0c3/django/db/models/fields/__init__.py#L2689

@thedrow
Copy link
Collaborator

thedrow commented Sep 5, 2024

@Grommash9 Care to fix this bug?

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

No branches or pull requests

3 participants