Opened 10 years ago

Closed 10 years ago

Last modified 10 years ago

#24339 closed Bug (fixed)

Exception at /add admin view when using DurationField

Reported by: Michael Angeletti Owned by: nobody
Component: Forms Version: 1.8alpha1
Severity: Release blocker Keywords:
Cc: Triage Stage: Ready for checkin
Has patch: yes Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: yes UI/UX: no

Description

Setup

Make an app with a model that has a DurationField. (started fresh app to verify)

Exception

AttributeError: 'NoneType' object has no attribute 'days' was the error message.

Cause

https://github.com/django/django/blob/0ed7d155635da9f79d4dd67e4889087d3673c6da/django/forms/fields.py#L517 (assumes value is a timedelta)

Solution

    def prepare_value(self, value):
        if isinstance(value, datetime.timedelta):
            return duration_string(value)
        return value

Change History (7)

comment:1 by Michael Angeletti, 10 years ago

Component: UncategorizedForms

comment:2 by Michael Angeletti, 10 years ago

Has patch: set

comment:3 by Claude Paroz, 10 years ago

Triage Stage: UnreviewedReady for checkin
Type: UncategorizedBug

comment:4 by Tim Graham <timograham@…>, 10 years ago

Resolution: fixed
Status: newclosed

In 8a21d250334f56845f255be5534b01d8c6eda314:

Fixed #24339 -- Fixed crash with empty DurationField form field.

comment:5 by Tim Graham <timograham@…>, 10 years ago

In 2e6d8e51db7c469ef32c7d00ff5aa7e68237f5f1:

[1.8.x] Fixed #24339 -- Fixed crash with empty DurationField form field.

Backport of 8a21d250334f56845f255be5534b01d8c6eda314 from master

comment:6 by Tim Graham <timograham@…>, 10 years ago

In 49647bec6e86b8d3d370ea1d8a80423185502c5a:

Added missing return value to DurationField.prepare_value(); refs #24339.

comment:7 by Tim Graham <timograham@…>, 10 years ago

In e13dca859cec90b7a04d51117fec5c18c6f90a9f:

[1.8.x] Added missing return value to DurationField.prepare_value(); refs #24339.

Backport of 49647bec6e86b8d3d370ea1d8a80423185502c5a from master

Note: See TracTickets for help on using tickets.
Back to Top