[Django] #32210: Django Admin with Inlines not using UUIDField default value

10 views
Skip to first unread message

Django

unread,
Nov 19, 2020, 12:21:48 PM11/19/20
to django-...@googlegroups.com
#32210: Django Admin with Inlines not using UUIDField default value
-----------------------------------------+------------------------
Reporter: joetheone | Owner: nobody
Type: Bug | Status: new
Component: contrib.admin | Version: 3.1
Severity: Normal | Keywords:
Triage Stage: Unreviewed | Has patch: 0
Needs documentation: 0 | Needs tests: 0
Patch needs improvement: 0 | Easy pickings: 0
UI/UX: 0 |
-----------------------------------------+------------------------
Hello,

I am a long time django user, first time bug reporter, so please let me
know if I need to do anything else to help get this bug fixed :)

I am using Django 3.1.3 and python 3.8.5 and have cerated a toy project to
illustrate the bug. I have the following models:


{{{
class UUIDModel(models.Model):
pkid = models.BigAutoField(primary_key=True, editable=False)
id = models.UUIDField(default=uuid.uuid4, editable=False, unique=True)

class Meta:
abstract = True

class Thing(UUIDModel):
name = models.CharField(max_length=191)

class SubThing(models.Model):
name = models.CharField(max_length=191)
thing = models.ForeignKey(
'bugapp.Thing',
to_field='id',
on_delete = models.CASCADE,
related_name='subthings',
)
}}}

And the following admin.py file:


{{{
class SubThingInline(admin.StackedInline):
model = SubThing

@admin.register(Thing)
class ThingAdmin(admin.ModelAdmin):
list_display = ('name',)
ordering = ('pkid',)
#search_fields = ('name',)
inlines = (SubThingInline,)
}}}

When logging into the admin, if you delete all of the entries for
"subthings", add a name, and save the model, it will work. As soon as you
try to add a subthing alongside the main Thing, it fails with the
following exception:

https://dpaste.com/8EU4FF6RW

It shows that the value of "id" in the Thing model is being set to null.

I believe this is a bug in django.

Thanks!

--
Ticket URL: <https://code.djangoproject.com/ticket/32210>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.

Django

unread,
Nov 19, 2020, 12:22:36 PM11/19/20
to django-...@googlegroups.com
#32210: Django Admin with Inlines not using UUIDField default value
-------------------------------+--------------------------------------

Reporter: joetheone | Owner: nobody
Type: Bug | Status: new
Component: contrib.admin | Version: 3.1
Severity: Normal | Resolution:

Keywords: | Triage Stage: Unreviewed
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------+--------------------------------------
Changes (by joetheone):

* Attachment "bugdemo.tbz" added.

I made a toy project containing all the code to reproduce the error and
zipped it.

Django

unread,
Nov 19, 2020, 12:23:40 PM11/19/20
to django-...@googlegroups.com
#32210: Django Admin with Inlines not using UUIDField default value
-------------------------------+--------------------------------------

Reporter: joetheone | Owner: nobody
Type: Bug | Status: new
Component: contrib.admin | Version: 3.1
Severity: Normal | Resolution:

Keywords: | Triage Stage: Unreviewed
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------+--------------------------------------
Description changed by joetheone:

Old description:

New description:

Hello,

inlines = (SubThingInline,)
}}}

When logging into the admin, if you delete all of the entries for
"subthings", add a name, and save the model, it will work. As soon as you
try to add a subthing alongside the main Thing, it fails with the
following exception:

https://dpaste.com/8EU4FF6RW

It shows that the value of "id" in the Thing model is being set to null.

I believe this is a bug in django.

Thanks!

--

--
Ticket URL: <https://code.djangoproject.com/ticket/32210#comment:1>

Django

unread,
Nov 20, 2020, 3:31:29 AM11/20/20
to django-...@googlegroups.com
#32210: Django Admin with Inlines not using UUIDField default value
----------------------------------+------------------------------------
Reporter: Joseph Metzinger | Owner: nobody
Type: Bug | Status: new
Component: Forms | Version: 3.1
Severity: Normal | Resolution:
Keywords: | Triage Stage: Accepted

Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
----------------------------------+------------------------------------
Changes (by Mariusz Felisiak):

* component: contrib.admin => Forms
* stage: Unreviewed => Accepted


Comment:

Thanks for the detailed report. I was able to reproduce this issue. It
looks that formsets' validation mutates the main object, because
`new_object.id` is not empty before the
[https://github.com/django/django/blob/fe9c7ded2996364f853c524b4421274717d89d5f/django/contrib/admin/options.py#L1584
all_valid()] call:
{{{
>>> new_object.id
e13fd82c-c3fc-42dc-ac12-577a4412ba51
>>> all_valid(formsets)
True
>>> new_object.id
None
}}}

Reproduced at ead37dfb580136cc27dbd487a1f1ad90c9235d15.

--
Ticket URL: <https://code.djangoproject.com/ticket/32210#comment:2>

Django

unread,
Nov 27, 2020, 9:19:14 AM11/27/20
to django-...@googlegroups.com
#32210: Django Admin with Inlines not using UUIDField default value
-------------------------------------+-------------------------------------
Reporter: Joseph Metzinger | Owner:
| Blackeyeforreal
Type: Bug | Status: assigned

Component: Forms | Version: 3.1
Severity: Normal | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by Blackeyeforreal):

* owner: nobody => Blackeyeforreal
* status: new => assigned


--
Ticket URL: <https://code.djangoproject.com/ticket/32210#comment:3>

Django

unread,
Jan 1, 2021, 4:18:07 AM1/1/21
to django-...@googlegroups.com
#32210: Django Admin with Inlines not using UUIDField default value
----------------------------------+------------------------------------
Reporter: Joseph Metzinger | Owner: (none)
Type: Bug | Status: new

Component: Forms | Version: 3.1
Severity: Normal | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
----------------------------------+------------------------------------
Changes (by Blackeyeforreal):

* owner: Blackeyeforreal => (none)
* status: assigned => new


--
Ticket URL: <https://code.djangoproject.com/ticket/32210#comment:4>

Django

unread,
Aug 7, 2021, 5:00:28 PM8/7/21
to django-...@googlegroups.com
#32210: Django Admin with Inlines not using UUIDField default value
----------------------------------+------------------------------------
Reporter: Joseph Metzinger | Owner: nobody
Type: Bug | Status: new

Component: Forms | Version: 3.1
Severity: Normal | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
----------------------------------+------------------------------------

Comment (by kamilturek):

Looks like it's not directly related to formsets' validation but
instantiating formset's forms.


{{{
(Pdb) new_object.id
UUID('06048350-3ad9-45f5-bca3-d08d795d7231')
(Pdb) formsets[0].forms
[<SubThingForm bound=True, valid=Unknown, fields=(name;thing;id;DELETE)>]
(Pdb) new_object.id
(Pdb)
}}}

{{{
(Pdb) new_object.id
UUID('652863a7-ccc8-4a18-9390-6fb77aa4bafa')
(Pdb) formsets[0]._construct_form(0)
<SubThingForm bound=True, valid=Unknown, fields=(name;thing;id;DELETE)>
(Pdb) new_object.id
(Pdb)
}}}

--
Ticket URL: <https://code.djangoproject.com/ticket/32210#comment:3>

Django

unread,
Aug 19, 2022, 2:13:22 PM8/19/22
to django-...@googlegroups.com
#32210: Django Admin with Inlines not using UUIDField default value
----------------------------------+------------------------------------
Reporter: Joseph Metzinger | Owner: (none)
Type: Bug | Status: assigned

Component: Forms | Version: 3.1
Severity: Normal | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
----------------------------------+------------------------------------
Changes (by NeErAj KuMaR):

* owner: nobody => (none)


* status: new => assigned


--
Ticket URL: <https://code.djangoproject.com/ticket/32210#comment:4>

Django

unread,
Aug 22, 2022, 3:10:34 PM8/22/22
to django-...@googlegroups.com
#32210: Django Admin with Inlines not using UUIDField default value
----------------------------------+------------------------------------
Reporter: Joseph Metzinger | Owner: (none)
Type: Bug | Status: assigned
Component: Forms | Version: 3.1
Severity: Normal | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
----------------------------------+------------------------------------

Comment (by NeErAj KuMaR):

The below code set id value **None** when formsets is_valid calling. so
need to stop set id value None when that field is not model's pk as
UUIDField.

{{{
if self.instance._state.adding:
if kwargs.get("to_field") is not None:
to_field =
self.instance._meta.get_field(kwargs["to_field"])
else:
to_field = self.instance._meta.pk
if to_field.has_default():
setattr(self.instance, to_field.attname, None)
}}}

--
Ticket URL: <https://code.djangoproject.com/ticket/32210#comment:5>

Django

unread,
Aug 22, 2022, 3:11:52 PM8/22/22
to django-...@googlegroups.com
#32210: Django Admin with Inlines not using UUIDField default value
----------------------------------+----------------------------------------
Reporter: Joseph Metzinger | Owner: NeErAj KuMaR

Type: Bug | Status: assigned
Component: Forms | Version: 3.1
Severity: Normal | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
----------------------------------+----------------------------------------
Changes (by NeErAj KuMaR):

* owner: (none) => NeErAj KuMaR


--
Ticket URL: <https://code.djangoproject.com/ticket/32210#comment:6>

Django

unread,
Aug 22, 2022, 4:00:07 PM8/22/22
to django-...@googlegroups.com
#32210: Django Admin with Inlines not using UUIDField default value
----------------------------------+----------------------------------------
Reporter: Joseph Metzinger | Owner: Neeraj Kumar

Type: Bug | Status: assigned
Component: Forms | Version: 3.1
Severity: Normal | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 1 | Needs documentation: 0

Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
----------------------------------+----------------------------------------
Changes (by Neeraj Kumar):

* has_patch: 0 => 1


Comment:

Check PR for this issue.

[https://github.com/django/django/pull/15983]

--
Ticket URL: <https://code.djangoproject.com/ticket/32210#comment:7>

Django

unread,
Aug 22, 2022, 4:02:32 PM8/22/22
to django-...@googlegroups.com
#32210: Django Admin with Inlines not using UUIDField default value
----------------------------------+----------------------------------------
Reporter: Joseph Metzinger | Owner: Neeraj Kumar
Type: Bug | Status: assigned
Component: Forms | Version: 3.1
Severity: Normal | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 1 | Needs documentation: 0

Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
----------------------------------+----------------------------------------
Changes (by Neeraj Kumar):

* cc: Neeraj Kumar (added)


--
Ticket URL: <https://code.djangoproject.com/ticket/32210#comment:8>

Django

unread,
Aug 22, 2022, 5:00:50 PM8/22/22
to django-...@googlegroups.com
#32210: Django Admin with Inlines not using UUIDField default value
----------------------------------+----------------------------------------
Reporter: Joseph Metzinger | Owner: Neeraj Kumar
Type: Bug | Status: assigned
Component: Forms | Version: 3.1
Severity: Normal | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 1 | Needs documentation: 0
Needs tests: 1 | Patch needs improvement: 1

Easy pickings: 0 | UI/UX: 0
----------------------------------+----------------------------------------
Changes (by David Wobrock):

* cc: David Wobrock (added)
* needs_better_patch: 0 => 1
* needs_tests: 0 => 1


--
Ticket URL: <https://code.djangoproject.com/ticket/32210#comment:9>

Django

unread,
Aug 23, 2022, 3:29:40 AM8/23/22
to django-...@googlegroups.com
#32210: Django Admin with Inlines not using UUIDField default value
----------------------------------+----------------------------------------
Reporter: Joseph Metzinger | Owner: Neeraj Kumar
Type: Bug | Status: assigned
Component: Forms | Version: 3.1
Severity: Normal | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 1 | Needs documentation: 0

Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
----------------------------------+----------------------------------------
Changes (by Neeraj Kumar):

* needs_better_patch: 1 => 0
* needs_tests: 1 => 0


--
Ticket URL: <https://code.djangoproject.com/ticket/32210#comment:10>

Django

unread,
Aug 23, 2022, 7:31:04 AM8/23/22
to django-...@googlegroups.com
#32210: Django Admin with Inlines not using UUIDField default value
----------------------------------+----------------------------------------
Reporter: Joseph Metzinger | Owner: Neeraj Kumar
Type: Bug | Status: assigned
Component: Forms | Version: 3.1
Severity: Normal | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 1 | Needs documentation: 0
Needs tests: 1 | Patch needs improvement: 0

Easy pickings: 0 | UI/UX: 0
----------------------------------+----------------------------------------
Changes (by Carlton Gibson):

* needs_tests: 0 => 1


--
Ticket URL: <https://code.djangoproject.com/ticket/32210#comment:11>

Django

unread,
Aug 23, 2022, 9:40:00 AM8/23/22
to django-...@googlegroups.com
#32210: Django Admin with Inlines not using UUIDField default value
----------------------------------+----------------------------------------
Reporter: Joseph Metzinger | Owner: Neeraj Kumar
Type: Bug | Status: assigned
Component: Forms | Version: 3.1
Severity: Normal | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 1 | Needs documentation: 0

Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
----------------------------------+----------------------------------------
Changes (by Carlton Gibson):

* needs_tests: 1 => 0


--
Ticket URL: <https://code.djangoproject.com/ticket/32210#comment:12>

Django

unread,
Oct 6, 2022, 6:24:24 AM10/6/22
to django-...@googlegroups.com
#32210: Django Admin with Inlines not using UUIDField default value
----------------------------------+----------------------------------------
Reporter: Joseph Metzinger | Owner: Neeraj Kumar
Type: Bug | Status: assigned
Component: Forms | Version: 3.1
Severity: Normal | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 1 | Needs documentation: 0
Needs tests: 1 | Patch needs improvement: 0

Easy pickings: 0 | UI/UX: 0
----------------------------------+----------------------------------------
Changes (by Carlton Gibson):

* needs_tests: 0 => 1


--
Ticket URL: <https://code.djangoproject.com/ticket/32210#comment:13>

Django

unread,
Jun 6, 2023, 4:49:54 PM6/6/23
to django-...@googlegroups.com
#32210: Django Admin with Inlines not using UUIDField default value
----------------------------------+----------------------------------------
Reporter: Joseph Metzinger | Owner: Neeraj Kumar
Type: Bug | Status: assigned
Component: Forms | Version: 3.1
Severity: Normal | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 1 | Needs documentation: 0
Needs tests: 1 | Patch needs improvement: 0

Easy pickings: 0 | UI/UX: 0
----------------------------------+----------------------------------------

Comment (by Bhuvnesh):

[https://github.com/django/django/pull/16950 PR]

--
Ticket URL: <https://code.djangoproject.com/ticket/32210#comment:14>

Django

unread,
Jun 10, 2023, 7:27:59 AM6/10/23
to django-...@googlegroups.com
#32210: Django Admin with Inlines not using UUIDField default value
----------------------------------+----------------------------------------
Reporter: Joseph Metzinger | Owner: Neeraj Kumar
Type: Bug | Status: assigned
Component: Forms | Version: 4.2

Severity: Normal | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 1 | Needs documentation: 0
Needs tests: 1 | Patch needs improvement: 0

Easy pickings: 0 | UI/UX: 0
----------------------------------+----------------------------------------
Changes (by Neeraj Kumar):

* version: 3.1 => 4.2


Comment:

Any update about this issue?

Added PR related to this issue.

This issue still exists in the latest version of Django.

--
Ticket URL: <https://code.djangoproject.com/ticket/32210#comment:15>

Django

unread,
Jun 19, 2023, 8:31:43 AM6/19/23
to django-...@googlegroups.com
#32210: Django Admin with Inlines not using UUIDField default value
----------------------------------+----------------------------------------
Reporter: Joseph Metzinger | Owner: Neeraj Kumar
Type: Bug | Status: assigned
Component: Forms | Version: 4.2
Severity: Normal | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 1 | Needs documentation: 0

Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
----------------------------------+----------------------------------------
Changes (by Natalia Bidart):

* needs_tests: 1 => 0


Comment:

Resetting the PR flags to ensure the new PR gets picked up in the review
queue.

--
Ticket URL: <https://code.djangoproject.com/ticket/32210#comment:16>

Django

unread,
Jul 5, 2023, 2:45:28 AM7/5/23
to django-...@googlegroups.com
#32210: Django Admin with Inlines not using UUIDField default value
----------------------------------+----------------------------------------
Reporter: Joseph Metzinger | Owner: Neeraj Kumar
Type: Bug | Status: assigned
Component: Forms | Version: 4.2
Severity: Normal | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 1 | Needs documentation: 0
Needs tests: 1 | Patch needs improvement: 1
Easy pickings: 0 | UI/UX: 0
----------------------------------+----------------------------------------
Changes (by Mariusz Felisiak):

* needs_better_patch: 0 => 1

* needs_tests: 0 => 1


--
Ticket URL: <https://code.djangoproject.com/ticket/32210#comment:17>

Django

unread,
Jul 7, 2023, 3:18:38 AM7/7/23
to django-...@googlegroups.com
#32210: Django Admin with Inlines not using UUIDField default value
-------------------------------------+-------------------------------------

Reporter: Joseph Metzinger | Owner: Neeraj
| Kumar
Type: Bug | Status: assigned
Component: Forms | Version: 4.2
Severity: Normal | Resolution:
Keywords: | Triage Stage: Ready for
| checkin
Has patch: 1 | Needs documentation: 0

Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by Mariusz Felisiak):

* needs_better_patch: 1 => 0


* needs_tests: 1 => 0

* stage: Accepted => Ready for checkin


--
Ticket URL: <https://code.djangoproject.com/ticket/32210#comment:18>

Django

unread,
Jul 7, 2023, 4:37:11 AM7/7/23
to django-...@googlegroups.com
#32210: Django Admin with Inlines not using UUIDField default value
-------------------------------------+-------------------------------------
Reporter: Joseph Metzinger | Owner: Neeraj
| Kumar
Type: Bug | Status: closed
Component: Forms | Version: 4.2
Severity: Normal | Resolution: fixed

Keywords: | Triage Stage: Ready for
| checkin
Has patch: 1 | Needs documentation: 0

Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by Mariusz Felisiak <felisiak.mariusz@…>):

* status: assigned => closed
* resolution: => fixed


Comment:

In [changeset:"eed096574fea5c9d82d0dc5952ad439dfde13718" eed0965]:
{{{
#!CommitTicketReference repository=""
revision="eed096574fea5c9d82d0dc5952ad439dfde13718"
Fixed #32210 -- Fixed model inlines with to_field that has a default.
}}}

--
Ticket URL: <https://code.djangoproject.com/ticket/32210#comment:19>

Reply all
Reply to author
Forward
0 new messages