Opened 10 years ago

Closed 10 years ago

Last modified 10 years ago

#24445 closed Bug (invalid)

DurationField with default='1 00:00' triggers validation on otherwise empty inline formsets

Reported by: Michael Angeletti Owned by: nobody
Component: Forms Version: dev
Severity: Normal Keywords:
Cc: Triage Stage: Unreviewed
Has patch: no Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

Description

When I reported #24391 I should have had the sense to check DurationField, but I didn't. Note, this isn't caused by a callable default argument, rather a string.

My initial thought is that this has something to do with the conversion process of a given string value into a timedelta, etc., but I haven't had a chance to really dig in, yet. I just barely finished work and I have to run a bunch of errands, or I'd dive straight into the code. However, I wanted to at least get the bug report in here right away.

Change History (6)

comment:1 by Michael Angeletti, 10 years ago

Component: UncategorizedForms
Type: UncategorizedBug
Version: 1.7master

comment:2 by Michael Angeletti, 10 years ago

Severity: NormalRelease blocker

I've set the severity to release blocker, since this is essentially the same regression (thought via different means) as #24391. I've looked through the code a bit and can't find anything obvious that could be causing this issue. I'm going to look some more tomorrow night.

comment:3 by Claude Paroz, 10 years ago

Severity: Release blockerNormal

In fact, you'll find the exact same behavior with current date-based fields. If you provide an initial or default value, you should provide a date/datetime Python value, not a string representation. By analogy, you should provide a timedelta value for your DurationField default value.

We *could* change that, other opinions welcome.

comment:4 by Tim Graham, 10 years ago

Resolution: wontfix
Status: newclosed

I don't see a need to complicate things by allowing differing types for defaults. Maybe there's an opportunity to use the checks framework to validate defaults are the proper type, but I'll leave that for a new ticket if someone wants to try implementing it.

comment:5 by Tim Graham, 10 years ago

Resolution: wontfixinvalid

comment:6 by Michael Angeletti, 10 years ago

@claudep @timgraham timedelta is obviously the right thing to use here, and I'm not sure what in the world I was thinking when I used a string. I think it was because I was getting so used to typing the string value into the admin, and just totally spaced it. I'm sorry for wasting a ticket and your time before simply taking 30 seconds to RTFM @ https://docs.djangoproject.com/en/1.8/ref/models/fields/#durationfield (which clearly states that the value is modeled in Python by timedelta).

Last edited 10 years ago by Michael Angeletti (previous) (diff)
Note: See TracTickets for help on using tickets.
Back to Top