Re: [Django] #37139: InlineAdmin breaks when using db_default on primary key field without a python default

8 views
Skip to first unread message

Django

unread,
Jun 3, 2026, 9:17:17 AM (3 days ago) Jun 3
to django-...@googlegroups.com
#37139: InlineAdmin breaks when using db_default on primary key field without a
python default
-------------------------------------+-------------------------------------
Reporter: Mariusz Felisiak | Owner: Mariusz
| Felisiak
Type: Bug | Status: assigned
Component: contrib.admin | Version: 5.2
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):

To be clear, inlines are involved, but `uuid` with `db_default` is in the
main object not in the inlines.

Replying to [comment:2 Jacob Walls]:
> Reproduced on 5.2 with a project that had an equivalent custom function.
I think admin inlines require having a python default on the field.

🤔 I'm not sure I bu that argument. This way we could copy code of all new
features to the older version of Django and say it doesn't work there so
it is not a bug in the function 😉😉, sure it's not a direct bug in
`UUID7()` but a long standing issue in handling `DatabaseDefault` in
inlines, however people will try to use new functions and hit the same. I
need to check carefully why we pass an empty parent instance to the inline
form etc., admin is not my area of expertise.
--
Ticket URL: <https://code.djangoproject.com/ticket/37139#comment:4>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.

Django

unread,
Jun 3, 2026, 9:54:08 AM (3 days ago) Jun 3
to django-...@googlegroups.com
#37139: InlineAdmin breaks when using db_default on primary key field without a
python default
-------------------------------------+-------------------------------------
Reporter: Mariusz Felisiak | Owner: Mariusz
| Felisiak
Type: Bug | Status: assigned
Component: contrib.admin | Version: 5.2
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 Jacob Walls):

I get that `db_default` is one of the main use cases for these new
functions. But I presume we already had this problem with `RandomUUID` in
`contrib.postgres`. The "new feature" here IMO is just the cross-database
abstraction to replace `RandomUUID`. (I'm motivated to get the fix in
before 6.1 beta, so the difference doesn't amount to much.)

----
I can get the add page to load when applying this tweak:
{{{#!diff
diff --git a/django/db/models/base.py b/django/db/models/base.py
index d53da600d7..21b9c80687 100644
--- a/django/db/models/base.py
+++ b/django/db/models/base.py
@@ -709,9 +709,10 @@ class Model(AltersData, metaclass=ModelBase):

def _is_pk_set(self, meta=None):
pk_val = self._get_pk_val(meta)
+ is_set = lambda val: val is None or isinstance(val,
DatabaseDefault)
return not (
- pk_val is None
- or (isinstance(pk_val, tuple) and any(f is None for f in
pk_val))
+ is_set(pk_val)
+ or (isinstance(pk_val, tuple) and any(is_set(f) for f in
pk_val))
)

def get_deferred_fields(self):
}}}

Obviously we'll need to check the other uses.
--
Ticket URL: <https://code.djangoproject.com/ticket/37139#comment:5>

Django

unread,
Jun 3, 2026, 9:57:42 AM (3 days ago) Jun 3
to django-...@googlegroups.com
#37139: InlineAdmin breaks when using db_default on primary key field without a
python default
-------------------------------------+-------------------------------------
Reporter: Mariusz Felisiak | Owner: Mariusz
| Felisiak
Type: Bug | Status: assigned
Component: contrib.admin | Version: 5.2
Severity: Release blocker | 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 Jacob Walls):

* severity: Normal => Release blocker

Comment:

Actually, I think this would qualify as a release blocker for 6.0 (via
valid user code or `RandomUUID`) under the "crashing bug" criterion.
--
Ticket URL: <https://code.djangoproject.com/ticket/37139#comment:6>

Django

unread,
Jun 3, 2026, 10:31:02 AM (3 days ago) Jun 3
to django-...@googlegroups.com
#37139: InlineAdmin breaks when using db_default on primary key field without a
python default
-------------------------------------+-------------------------------------
Reporter: Mariusz Felisiak | Owner: Mariusz
| Felisiak
Type: Bug | Status: assigned
Component: contrib.admin | Version: 5.2
Severity: Release blocker | 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

Comment:

Thanks for the report and for taking a look!
--
Ticket URL: <https://code.djangoproject.com/ticket/37139#comment:7>

Django

unread,
Jun 4, 2026, 2:11:36 PM (2 days ago) Jun 4
to django-...@googlegroups.com
#37139: InlineAdmin breaks when using db_default on primary key field without a
python default
-------------------------------------+-------------------------------------
Reporter: Mariusz Felisiak | Owner: Mariusz
| Felisiak
Type: Bug | Status: assigned
Component: contrib.admin | Version: 5.2
Severity: Release blocker | 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/21420 PR]
--
Ticket URL: <https://code.djangoproject.com/ticket/37139#comment:8>

Django

unread,
Jun 4, 2026, 3:09:51 PM (2 days ago) Jun 4
to django-...@googlegroups.com
#37139: InlineAdmin breaks when using db_default on primary key field without a
python default
-------------------------------------+-------------------------------------
Reporter: Mariusz Felisiak | Owner: Mariusz
| Felisiak
Type: Bug | Status: assigned
Component: contrib.admin | Version: 5.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 Jacob Walls):

* severity: Release blocker => Normal
* stage: Accepted => Ready for checkin

Comment:

This change has the potential to start raising sanity-check style errors
("cannot do X operation on unsaved objects") in some cases, so it's not
really a good candidate for a backport to a stable version.
--
Ticket URL: <https://code.djangoproject.com/ticket/37139#comment:9>

Django

unread,
Jun 5, 2026, 6:10:21 AM (yesterday) Jun 5
to django-...@googlegroups.com
#37139: InlineAdmin breaks when using db_default on primary key field without a
python default
-------------------------------------+-------------------------------------
Reporter: Mariusz Felisiak | Owner: Mariusz
| Felisiak
Type: Bug | Status: closed
Component: contrib.admin | Version: 5.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 GitHub <noreply@…>):

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

Comment:

In [changeset:"a2348c85fc6c20087935c74cd99340dd4ef2dcdc" a2348c85]:
{{{#!CommitTicketReference repository=""
revision="a2348c85fc6c20087935c74cd99340dd4ef2dcdc"
Fixed #37139 -- Fixed inlines crash on parent models with db_default on
primary key.
}}}
--
Ticket URL: <https://code.djangoproject.com/ticket/37139#comment:10>

Django

unread,
Jun 5, 2026, 6:11:50 AM (yesterday) Jun 5
to django-...@googlegroups.com
#37139: InlineAdmin breaks when using db_default on primary key field without a
python default
-------------------------------------+-------------------------------------
Reporter: Mariusz Felisiak | Owner: Mariusz
| Felisiak
Type: Bug | Status: closed
Component: contrib.admin | Version: 5.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
-------------------------------------+-------------------------------------
Comment (by Mariusz Felisiak <felisiak.mariusz@…>):

In [changeset:"c3a3ea7bed4d162ec8efa426b48d31ba9f37a82d" c3a3ea7]:
{{{#!CommitTicketReference repository=""
revision="c3a3ea7bed4d162ec8efa426b48d31ba9f37a82d"
[6.1.x] Fixed #37139 -- Fixed inlines crash on parent models with
db_default on primary key.

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