#32577: Add support for `UUIDAutoField` `DEFAULT_AUTO_FIELD`
-------------------------------------+-------------------------------------
Reporter: Tomasz Wójcik | Owner: Tomasz
| Wójcik
Type: New feature | Status: assigned
Component: Database layer | Version: dev
(models, ORM) |
Severity: Normal | Resolution:
Keywords: uuid autofield | Triage Stage: Accepted
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Comment (by Tomasz Wójcik):
Replying to [comment:37 Simon Charette]:
> Maybe a naive question but what purpose does a Postgres specific
`UUID4Field` provides now that we generically support defining a primary
key field with a `db_default` and have it returned by the database using
`RETURNING` on all backends that support it?
Not much. I'm fine with dropping it, if that's desired. My goal is to just
enable custom auto field.
Replying to [comment:37 Simon Charette]:
> and why chose UUIDv4 specifically now that UUIDv7 is most likely a
better candidate?
That's very subjective and that's the goal here. Let's allow everyone to
use what they want. I'd prefer (or even be limited to) UUIDv4 in most of
the projects I was working with.
Replying to [comment:37 Simon Charette]:
> From looking back at #31007 it seems that having a setting that was not
tailored to `AutoFieldMixin` subclasses was agreed upon
[https://groups.google.com/g/django-
developers/c/MBPEPKlibGQ/m/F4i6JPvBAAAJ on the mailing list] and well as
[https://github.com/django/django/pull/13179#discussion_r461779004 during
the first phase of the implementation] but we
[https://github.com/django/django/pull/13179#discussion_r463988623 then
took a different route].
>
> Looking back at the current state of things now I think would be much
more value in allowing any fields to be used for a `DEFAULT_PK_FIELD`,
deprecate `DEFAULT_AUTO_FIELD`, and provide a database agnostic
`RandomUUID` database function that can be used on SQLite, Postgres,
MySQL, and Oracle so the requested feature here can be implemented as
>
> {{{#!python
> # core/fields.py
> class UUIDPrimaryKeyField(models.UUIDField):
> def __init__(self, *args, **kwargs):
> kwargs["primary_key"] = True
> kwargs.setdefault("db_default", RandomUUID())
>
> # settings.py
> DEFAULT_PK_FIELD = "core.fields.UUIDPrimaryKeyField"
> }}}
I was not aware of this and it sounds good. Thank you for providing more
context.
--
Ticket URL: <https://code.djangoproject.com/ticket/32577#comment:41>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.
--
You received this message because you are subscribed to the Google Groups
"Django updates" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To view this discussion visit
https://groups.google.com/d/msgid/django-updates/01070196735df91c-af3362c4-e450-45cf-8971-c9687cb78c80-000000%40eu-central-1.amazonses.com.