[Django] #37147: Empty form for inlines breaks when using db_default on primary key field

9 views
Skip to first unread message

Django

unread,
Jun 7, 2026, 6:57:02 AM (2 days ago) Jun 7
to django-...@googlegroups.com
#37147: Empty form for inlines breaks when using db_default on primary key field
-------------------------------------+-------------------------------------
Reporter: Mariusz | Owner: Mariusz Felisiak
Felisiak |
Type: Bug | Status: assigned
Component: Forms | Version: 6.0
Severity: Normal | Keywords:
Triage Stage: | Has patch: 0
Unreviewed |
Needs documentation: 0 | Needs tests: 0
Patch needs improvement: 0 | Easy pickings: 0
UI/UX: 0 |
-------------------------------------+-------------------------------------
Using `db_default` with the new `UUID4` or `UUID7` functions breaks saving
inlines. For example,

- `models.py`
{{{#!python
class MyMain(models.Model):
uuid = models.UUIDField(primary_key=True, db_default=UUID7(),
editable=False, verbose_name="UUID")
name = models.CharField(max_length=100)

class MyChild(models.Model):
name = models.CharField(max_length=100)
parent = models.ForeignKey(MyMain, models.DB_CASCADE)
}}}

- `admin.py`

{{{#!python
class ChildAdmin(admin.TabularInline):
model = MyChild
extra = 0


class MainAdmin(admin.ModelAdmin):
inlines = [ChildAdmin]


admin.site.register(MyChild)
admin.site.register(MyMain, MainAdmin)
}}}

`DatabaseDefault` instances are rendered as values of the parent fields:

{{{
<tr class="form-row empty-form" id="mychild_set-empty">
<td class="original">
<input type="hidden" name="mychild_set-__prefix__-id" id
="id_mychild_set-__prefix__-id">
<input type="hidden" name="mychild_set-__prefix__-parent"
value="&lt;django.db.models.expressions.DatabaseDefault object at
0x750a2aa14ad0&gt;" id="id_mychild_set-__prefix__-parent">
</td>
...
}}}
which causes the following error when trying to save:
{{{
[{'parent': ['The inline value did not match the parent instance.']}]
}}}
--
Ticket URL: <https://code.djangoproject.com/ticket/37147>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.

Django

unread,
Jun 7, 2026, 7:04:48 AM (2 days ago) Jun 7
to django-...@googlegroups.com
#37147: Empty form for inlines breaks when using db_default on primary key field
-------------------------------------+-------------------------------------
Reporter: Mariusz Felisiak | Owner: Mariusz
| Felisiak
Type: Bug | Status: assigned
Component: Forms | Version: 6.0
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
-------------------------------------+-------------------------------------
Comment (by Mariusz Felisiak):

The following fixes this issue for me:
{{{#!diff
diff --git a/django/forms/widgets.py b/django/forms/widgets.py
index f401896b60..140bd3e395 100644
--- a/django/forms/widgets.py
+++ b/django/forms/widgets.py
@@ -343,7 +343,9 @@ class Widget(metaclass=MediaDefiningClass):
"""
Return a value as it should appear when rendered in a template.
"""
- if value == "" or value is None:
+ from django.db.models.expressions import DatabaseDefault
+
+ if value == "" or value is None or isinstance(value,
DatabaseDefault):
return None
if self.is_localized:
return formats.localize_input(value)
}}}
--
Ticket URL: <https://code.djangoproject.com/ticket/37147#comment:1>

Django

unread,
Jun 7, 2026, 9:23:41 AM (2 days ago) Jun 7
to django-...@googlegroups.com
#37147: Empty form for inlines breaks when using db_default on primary key field
-------------------------------------+-------------------------------------
Reporter: Mariusz Felisiak | Owner: Mariusz
| Felisiak
Type: Bug | Status: assigned
Component: Forms | Version: 6.0
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 Jacob Walls):

* stage: Unreviewed => Accepted

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

Django

unread,
Jun 7, 2026, 12:04:23 PM (2 days ago) Jun 7
to django-...@googlegroups.com
#37147: Empty form for inlines breaks when using db_default on primary key field
-------------------------------------+-------------------------------------
Reporter: Mariusz Felisiak | Owner: Mariusz
| Felisiak
Type: Bug | Status: assigned
Component: Forms | Version: 6.0
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 Mariusz Felisiak):

* has_patch: 0 => 1

Comment:

[https://github.com/django/django/pull/21427 PR]
--
Ticket URL: <https://code.djangoproject.com/ticket/37147#comment:3>

Django

unread,
Jun 8, 2026, 4:06:11 PM (21 hours ago) Jun 8
to django-...@googlegroups.com
#37147: Empty form for inlines breaks when using db_default on primary key field
-------------------------------------+-------------------------------------
Reporter: Mariusz Felisiak | Owner: Mariusz
| Felisiak
Type: Bug | Status: assigned
Component: Forms | Version: 6.0
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 Jacob Walls):

* stage: Accepted => Ready for checkin

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

Django

unread,
7:12 AM (6 hours ago) 7:12 AM
to django-...@googlegroups.com
#37147: Empty form for inlines breaks when using db_default on primary key field
-------------------------------------+-------------------------------------
Reporter: Mariusz Felisiak | Owner: Mariusz
| Felisiak
Type: Bug | Status: closed
Component: Forms | Version: 6.0
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 GitHub <noreply@…>):

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

Comment:

In [changeset:"71af23d1f4678c4bf052e051d72e8928e1697de3" 71af23d]:
{{{#!CommitTicketReference repository=""
revision="71af23d1f4678c4bf052e051d72e8928e1697de3"
Fixed #37147 -- Fixed rendering empty values for models with db_default on
primary key.
}}}
--
Ticket URL: <https://code.djangoproject.com/ticket/37147#comment:5>

Django

unread,
7:14 AM (6 hours ago) 7:14 AM
to django-...@googlegroups.com
#37147: Empty form for inlines breaks when using db_default on primary key field
-------------------------------------+-------------------------------------
Reporter: Mariusz Felisiak | Owner: Mariusz
| Felisiak
Type: Bug | Status: closed
Component: Forms | Version: 6.0
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
-------------------------------------+-------------------------------------
Comment (by Mariusz Felisiak <felisiak.mariusz@…>):

In [changeset:"1720b7b240c71367eaed2cbce9be54b4e01ae23b" 1720b7b]:
{{{#!CommitTicketReference repository=""
revision="1720b7b240c71367eaed2cbce9be54b4e01ae23b"
[6.1.x] Fixed #37147 -- Fixed rendering empty values for models with
db_default on primary key.

Backport of 71af23d1f4678c4bf052e051d72e8928e1697de3 from main
}}}
--
Ticket URL: <https://code.djangoproject.com/ticket/37147#comment:6>
Reply all
Reply to author
Forward
0 new messages