Opened 6 years ago

Closed 6 years ago

#29869 closed Cleanup/optimization (fixed)

UUIDField.to_python() should convert int values

Reported by: thenewguy Owned by: Sanyam Khurana
Component: Database layer (models, ORM) Version: 2.1
Severity: Normal Keywords:
Cc: Triage Stage: Ready for checkin
Has patch: yes Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

Description

It would be handy if UUIDField.to_python() could handle integer values. This has practical application when using generic foreign keys in a project that mixes auto fields and uuid primary keys. The generic id field could be set to a BigIntegerField and then could point to uuid or integer primary keys

https://github.com/django/django/blob/master/django/db/models/fields/__init__.py#L2320

Change History (7)

comment:1 by Tim Graham, 6 years ago

Component: UncategorizedDatabase layer (models, ORM)
Summary: UUIDField to_python should convert int valuesUUIDField.to_python() should convert int values
Type: UncategorizedCleanup/optimization

How would the conversion work?

comment:2 by thenewguy, 6 years ago

uuid.UUID(int=value) worked for me but I haven't tested any cases yet

comment:3 by Simon Charette, 6 years ago

Triage Stage: UnreviewedAccepted

Accepting on the basis that I could see it being useful when migrating a project from sequence based to uuid primary keys.

comment:4 by Sanyam Khurana, 6 years ago

Owner: changed from nobody to Sanyam Khurana
Status: newassigned

comment:5 by Sanyam Khurana, 6 years ago

Has patch: set

I've added a patch for this here: https://github.com/django/django/pull/10557

comment:6 by Simon Charette, 6 years ago

Triage Stage: AcceptedReady for checkin

Marking as RFC given I'm not sure this is worth a mention in the release notes.

comment:7 by Tim Graham <timograham@…>, 6 years ago

Resolution: fixed
Status: assignedclosed

In 83c7096f:

Fixed #29869 -- Made UUIDField.to_python() convert integers.

Note: See TracTickets for help on using tickets.
Back to Top