[Django] #35628: date_hierarchy doesn't support GenerateField with output_field set to DateTimeField or DateField

15 views
Skip to first unread message

Django

unread,
Jul 24, 2024, 2:41:47 PM7/24/24
to django-...@googlegroups.com
#35628: date_hierarchy doesn't support GenerateField with output_field set to
DateTimeField or DateField
-----------------------------+-----------------------------------------
Reporter: john-parton | Type: Bug
Status: new | Component: contrib.admin
Version: 5.0 | 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
-----------------------------+-----------------------------------------
If you have a GeneratedField with output_field set to DateField or
DateTimeField, you cannot use it in the admin as a `date_hierarchy`
because of a check. If you skip the check, it actually works just fine in
my testing. I believe this the check could be adjusted to account for
this.


{{{
# models.py
class TestModel(models.Model):
date_range = DateTimeRangeField(_("Date range"))
start_date = models.GeneratedField(
expression=Lower("date_range"),
output_field=models.DateTimeField(),
db_persist=True,
)



# admin.py
class TestAdmin(admin.ModelAdmin):
date_hierarchy = "start_date"

# Skipping checks actually makes this work exactly correctly
def check(self, *args, **kwargs):
return ()

}}}

I'll see if I can whip up a patch.
--
Ticket URL: <https://code.djangoproject.com/ticket/35628>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.

Django

unread,
Jul 24, 2024, 2:59:42 PM7/24/24
to django-...@googlegroups.com
#35628: date_hierarchy doesn't support GenerateField with output_field set to
DateTimeField or DateField
-------------------------------+--------------------------------------
Reporter: john-parton | Owner: (none)
Type: Bug | Status: new
Component: contrib.admin | Version: 5.0
Severity: Normal | Resolution:
Keywords: | Triage Stage: Unreviewed
Has patch: 1 | Needs documentation: 1
Needs tests: 1 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------+--------------------------------------
Changes (by john-parton):

* has_patch: 0 => 1
* needs_docs: 0 => 1
* needs_tests: 0 => 1


Old description:

> If you have a GeneratedField with output_field set to DateField or
> DateTimeField, you cannot use it in the admin as a `date_hierarchy`
> because of a check. If you skip the check, it actually works just fine in
> my testing. I believe this the check could be adjusted to account for
> this.
>

> {{{
> # models.py
> class TestModel(models.Model):
> date_range = DateTimeRangeField(_("Date range"))
> start_date = models.GeneratedField(
> expression=Lower("date_range"),
> output_field=models.DateTimeField(),
> db_persist=True,
> )
>

>
> # admin.py
> class TestAdmin(admin.ModelAdmin):
> date_hierarchy = "start_date"
>
> # Skipping checks actually makes this work exactly correctly
> def check(self, *args, **kwargs):
> return ()
>
> }}}
>
> I'll see if I can whip up a patch.

New description:

If you have a GeneratedField with output_field set to DateField or
DateTimeField, you cannot use it in the admin as a `date_hierarchy`
because of a check. If you skip the check, it actually works just fine in
my testing. I believe this the check could be adjusted to account for
this.


{{{
# models.py
class TestModel(models.Model):
date_range = DateTimeRangeField(_("Date range"))
start_date = models.GeneratedField(
expression=Lower("date_range"),
output_field=models.DateTimeField(),
db_persist=True,
)



# admin.py
class TestAdmin(admin.ModelAdmin):
date_hierarchy = "start_date"

# Skipping checks actually makes this work exactly correctly
def check(self, *args, **kwargs):
return ()

}}}

I'll see if I can whip up a patch.

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

Django

unread,
Jul 24, 2024, 3:00:02 PM7/24/24
to django-...@googlegroups.com
#35628: date_hierarchy doesn't support GenerateField with output_field set to
DateTimeField or DateField
-------------------------------+--------------------------------------
Reporter: john-parton | Owner: (none)
Type: Bug | Status: new
Component: contrib.admin | Version: 5.0
Severity: Normal | Resolution:
Keywords: | Triage Stage: Unreviewed
Has patch: 1 | Needs documentation: 1
Needs tests: 1 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------+--------------------------------------
Comment (by john-parton):

Initial patch here: https://github.com/django/django/pull/18407

No docs or tests yet.
--
Ticket URL: <https://code.djangoproject.com/ticket/35628#comment:2>

Django

unread,
Jul 24, 2024, 3:38:20 PM7/24/24
to django-...@googlegroups.com
#35628: date_hierarchy doesn't support GenerateField with output_field set to
DateTimeField or DateField
---------------------------------+------------------------------------
Reporter: john-parton | Owner: (none)
Type: Bug | Status: new
Component: contrib.admin | Version: 5.0
Severity: Release blocker | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 1 | Needs documentation: 1
Needs tests: 1 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
---------------------------------+------------------------------------
Changes (by Simon Charette):

* severity: Normal => Release blocker
* stage: Unreviewed => Accepted

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

Django

unread,
Jul 25, 2024, 8:01:16 AM7/25/24
to django-...@googlegroups.com
#35628: date_hierarchy doesn't support GenerateField with output_field set to
DateTimeField or DateField
---------------------------------+---------------------------------------
Reporter: john-parton | Owner: john-parton
Type: Bug | Status: assigned
Component: contrib.admin | Version: 5.0
Severity: Release blocker | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 1 | Needs documentation: 1
Needs tests: 1 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
---------------------------------+---------------------------------------
Changes (by Sarah Boyce):

* owner: (none) => john-parton
* status: new => assigned

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

Django

unread,
Aug 4, 2024, 4:36:14 AM8/4/24
to django-...@googlegroups.com
#35628: date_hierarchy doesn't support GenerateField with output_field set to
DateTimeField or DateField
-------------------------------------+-------------------------------------
Reporter: john-parton | Owner: john-
| parton
Type: Bug | Status: assigned
Component: contrib.admin | Version: 5.0
Severity: Release blocker | 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 Claude Paroz):

* needs_docs: 1 => 0
* needs_tests: 1 => 0
* stage: Accepted => Ready for checkin

Comment:

Waiting for a final OK from Simon.
--
Ticket URL: <https://code.djangoproject.com/ticket/35628#comment:5>

Django

unread,
Aug 5, 2024, 9:27:30 AM8/5/24
to django-...@googlegroups.com
#35628: date_hierarchy doesn't support GenerateField with output_field set to
DateTimeField or DateField
-------------------------------------+-------------------------------------
Reporter: john-parton | Owner: john-
| parton
Type: Bug | Status: closed
Component: contrib.admin | Version: 5.0
Severity: Release blocker | 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 Sarah Boyce <42296566+sarahboyce@…>):

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

Comment:

In [changeset:"7f8d839722b72aeb3ec5a4278ae57c18283acacd" 7f8d8397]:
{{{#!CommitTicketReference repository=""
revision="7f8d839722b72aeb3ec5a4278ae57c18283acacd"
Fixed #35628 -- Allowed compatible GeneratedFields for
ModelAdmin.date_hierarchy.
}}}
--
Ticket URL: <https://code.djangoproject.com/ticket/35628#comment:6>

Django

unread,
Aug 5, 2024, 9:29:32 AM8/5/24
to django-...@googlegroups.com
#35628: date_hierarchy doesn't support GenerateField with output_field set to
DateTimeField or DateField
-------------------------------------+-------------------------------------
Reporter: john-parton | Owner: john-
| parton
Type: Bug | Status: closed
Component: contrib.admin | Version: 5.0
Severity: Release blocker | 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 Sarah Boyce <42296566+sarahboyce@…>):

In [changeset:"88ebcb1856deef5ab777601a735c9954ac723325" 88ebcb1]:
{{{#!CommitTicketReference repository=""
revision="88ebcb1856deef5ab777601a735c9954ac723325"
[5.1.x] Fixed #35628 -- Allowed compatible GeneratedFields for
ModelAdmin.date_hierarchy.

Backport of 7f8d839722b72aeb3ec5a4278ae57c18283acacd from main.
}}}
--
Ticket URL: <https://code.djangoproject.com/ticket/35628#comment:7>

Django

unread,
Aug 5, 2024, 9:31:18 AM8/5/24
to django-...@googlegroups.com
#35628: date_hierarchy doesn't support GenerateField with output_field set to
DateTimeField or DateField
-------------------------------------+-------------------------------------
Reporter: john-parton | Owner: john-
| parton
Type: Bug | Status: closed
Component: contrib.admin | Version: 5.0
Severity: Release blocker | 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 Sarah Boyce <42296566+sarahboyce@…>):

In [changeset:"c822ad638a746c4f2bcc2629586aca1cb03cb513" c822ad6]:
{{{#!CommitTicketReference repository=""
revision="c822ad638a746c4f2bcc2629586aca1cb03cb513"
[5.0.x] Fixed #35628 -- Allowed compatible GeneratedFields for
ModelAdmin.date_hierarchy.

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