#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 , 10 years ago
Component: | Uncategorized → Forms |
---|---|
Type: | Uncategorized → Bug |
Version: | 1.7 → master |
comment:2 by , 10 years ago
Severity: | Normal → Release blocker |
---|
comment:3 by , 10 years ago
Severity: | Release blocker → Normal |
---|
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 , 10 years ago
Resolution: | → wontfix |
---|---|
Status: | new → closed |
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 , 10 years ago
Resolution: | wontfix → invalid |
---|
comment:6 by , 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
).
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.