[Django] #37168: Readonly fields with db_default display DatabaseDefault representation

11 views
Skip to first unread message

Django

unread,
Jun 13, 2026, 6:50:18 AMJun 13
to django-...@googlegroups.com
#37168: Readonly fields with db_default display DatabaseDefault representation
-------------------------------------+-------------------------------------
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 |
-------------------------------------+-------------------------------------
Readonly fields with `db_default` display `DatabaseDefault()`
representation in the admin. For example:

- `models.py`
{{{#!python
class MyModel(models.Model):
uuid = models.UUIDField(db_default=UUID7(), editable=False,
primary_key=True)
created_datetime = models.DateTimeField(db_default=Now(),
editable=False)
modified_datetime = models.DateTimeField(db_default=Now(),
editable=False)
name = models.TextField()
}}}

- `admin.py`

{{{#!python
@admin.register(MyModel)
class MyModelAdmin(admin.ModelAdmin):
readonly_fields = ["uuid", "created_datetime", "modified_datetime"]
}}}


I think they should be consider as any other empty values.
--
Ticket URL: <https://code.djangoproject.com/ticket/37168>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.

Django

unread,
Jun 13, 2026, 6:51:29 AMJun 13
to django-...@googlegroups.com
#37168: Readonly fields with db_default display DatabaseDefault representation
-------------------------------------+-------------------------------------
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
-------------------------------------+-------------------------------------
Changes (by Mariusz Felisiak):

* Attachment "Screenshot_20260613_125111.png" added.

Django

unread,
Jun 13, 2026, 6:52:29 AMJun 13
to django-...@googlegroups.com
#37168: Readonly fields with db_default display DatabaseDefault representation
-------------------------------------+-------------------------------------
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
-------------------------------------+-------------------------------------
Description changed by Mariusz Felisiak:

Old description:

> Readonly fields with `db_default` display `DatabaseDefault()`
> representation in the admin. For example:
>
> - `models.py`
> {{{#!python
> class MyModel(models.Model):
> uuid = models.UUIDField(db_default=UUID7(), editable=False,
> primary_key=True)
> created_datetime = models.DateTimeField(db_default=Now(),
> editable=False)
> modified_datetime = models.DateTimeField(db_default=Now(),
> editable=False)
> name = models.TextField()
> }}}
>
> - `admin.py`
>
> {{{#!python
> @admin.register(MyModel)
> class MyModelAdmin(admin.ModelAdmin):
> readonly_fields = ["uuid", "created_datetime", "modified_datetime"]
> }}}
>

> I think they should be consider as any other empty values.

New description:

Readonly fields with `db_default` display `DatabaseDefault()`
representation in the admin. For example:

- `models.py`
{{{#!python
class MyModel(models.Model):
uuid = models.UUIDField(db_default=UUID7(), editable=False,
primary_key=True)
created_datetime = models.DateTimeField(db_default=Now(),
editable=False)
modified_datetime = models.DateTimeField(db_default=Now(),
editable=False)
name = models.TextField()
}}}

- `admin.py`

{{{#!python
@admin.register(MyModel)
class MyModelAdmin(admin.ModelAdmin):
readonly_fields = ["uuid", "created_datetime", "modified_datetime"]
}}}

[[Image(Screenshot_20260613_125111.png​)]]
I think they should be consider as any other empty values.

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

Django

unread,
Jun 13, 2026, 12:06:41 PMJun 13
to django-...@googlegroups.com
#37168: Readonly fields with db_default display DatabaseDefault representation
-------------------------------------+-------------------------------------
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):

We wanted to add `DatabaseDefault()` to the list of `Field.empty_values`
and modify its `__hash__` and `__eq__`. Unfortunately, there is an issue
in importing `DatabaseDefault` anywhere in the `forms` module and
`expression` is required to initialize `DatabaseDefault`. I'm thinking
about adding `is_value_empty()` hook to the `Field`:
{{{#!python
def is_value_empty(self, value):
return value in self.empty_values or isinstance(value,
DatabaseDefault):
}}}
and reusing it everywhere we currently check `if value in
self.empty_values`.
--
Ticket URL: <https://code.djangoproject.com/ticket/37168#comment:2>

Django

unread,
Jun 13, 2026, 1:59:09 PMJun 13
to django-...@googlegroups.com
#37168: Readonly fields with db_default display DatabaseDefault representation
-------------------------------------+-------------------------------------
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
-------------------------------------+-------------------------------------
Changes (by Mariusz Felisiak):

* Attachment "ticket_37168.zip" added.

Django

unread,
Jun 15, 2026, 11:26:59 AM (13 days ago) Jun 15
to django-...@googlegroups.com
#37168: Readonly fields with db_default display DatabaseDefault representation
-------------------------------------+-------------------------------------
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

Comment:

Thanks for the report. The hook does sound better than a misleading
`__eq__()`!
--
Ticket URL: <https://code.djangoproject.com/ticket/37168#comment:3>

Django

unread,
Jun 16, 2026, 12:07:47 PM (12 days ago) Jun 16
to django-...@googlegroups.com
#37168: Readonly fields with db_default display DatabaseDefault representation
-------------------------------------+-------------------------------------
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/21495 PR]
--
Ticket URL: <https://code.djangoproject.com/ticket/37168#comment:4>

Django

unread,
Jun 17, 2026, 12:19:28 PM (11 days ago) Jun 17
to django-...@googlegroups.com
#37168: Readonly fields with db_default display DatabaseDefault representation
-------------------------------------+-------------------------------------
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: 1 | Patch needs improvement: 1
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by Jacob Walls):

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

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

Django

unread,
Jun 17, 2026, 3:49:00 PM (11 days ago) Jun 17
to django-...@googlegroups.com
#37168: Readonly fields with db_default display DatabaseDefault representation
-------------------------------------+-------------------------------------
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: 1 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by Mariusz Felisiak):

* needs_better_patch: 1 => 0

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

Django

unread,
Jun 17, 2026, 5:19:51 PM (11 days ago) Jun 17
to django-...@googlegroups.com
#37168: Readonly fields with db_default display DatabaseDefault representation
-------------------------------------+-------------------------------------
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):

* needs_tests: 1 => 0

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

Django

unread,
Jun 17, 2026, 5:30:32 PM (11 days ago) Jun 17
to django-...@googlegroups.com
#37168: Readonly fields with db_default display DatabaseDefault representation
-------------------------------------+-------------------------------------
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/37168#comment:8>

Django

unread,
Jun 18, 2026, 12:35:26 PM (10 days ago) Jun 18
to django-...@googlegroups.com
#37168: Readonly fields with db_default display DatabaseDefault representation
-------------------------------------+-------------------------------------
Reporter: Mariusz Felisiak | Owner: Mariusz
| Felisiak
Type: Bug | Status: assigned
Component: contrib.admin | Version: 6.0
Severity: Normal | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 1
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by Jacob Walls):

* component: Forms => contrib.admin
* needs_better_patch: 0 => 1
* stage: Ready for checkin => Accepted

Comment:

After review, I think adjusting the admin hooks only is safest.
--
Ticket URL: <https://code.djangoproject.com/ticket/37168#comment:9>

Django

unread,
Jun 18, 2026, 2:14:46 PM (10 days ago) Jun 18
to django-...@googlegroups.com
#37168: Readonly fields with db_default display DatabaseDefault representation
-------------------------------------+-------------------------------------
Reporter: Mariusz Felisiak | Owner: Mariusz
| Felisiak
Type: Bug | Status: assigned
Component: contrib.admin | 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):

* needs_better_patch: 1 => 0

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

Django

unread,
Jun 18, 2026, 2:53:20 PM (10 days ago) Jun 18
to django-...@googlegroups.com
#37168: Readonly fields with db_default display DatabaseDefault representation
-------------------------------------+-------------------------------------
Reporter: Mariusz Felisiak | Owner: Mariusz
| Felisiak
Type: Bug | Status: assigned
Component: contrib.admin | 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/37168#comment:11>

Django

unread,
Jun 18, 2026, 3:00:55 PM (10 days ago) Jun 18
to django-...@googlegroups.com
#37168: Readonly fields with db_default display DatabaseDefault representation
-------------------------------------+-------------------------------------
Reporter: Mariusz Felisiak | Owner: Mariusz
| Felisiak
Type: Bug | Status: closed
Component: contrib.admin | 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:"77d0c9d549a8d95156c833eceb6275d9b7317d4e" 77d0c9d]:
{{{#!CommitTicketReference repository=""
revision="77d0c9d549a8d95156c833eceb6275d9b7317d4e"
Fixed #37168 -- Made admin display database defaults as empty values.
}}}
--
Ticket URL: <https://code.djangoproject.com/ticket/37168#comment:12>

Django

unread,
Jun 18, 2026, 3:03:03 PM (10 days ago) Jun 18
to django-...@googlegroups.com
#37168: Readonly fields with db_default display DatabaseDefault representation
-------------------------------------+-------------------------------------
Reporter: Mariusz Felisiak | Owner: Mariusz
| Felisiak
Type: Bug | Status: closed
Component: contrib.admin | 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:"a5405b87616c1a53e0e3823916dd9016b9cf5ac7" a5405b87]:
{{{#!CommitTicketReference repository=""
revision="a5405b87616c1a53e0e3823916dd9016b9cf5ac7"
[6.1.x] Fixed #37168 -- Made admin display database defaults as empty
values.

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