#12467 closed New feature (fixed)
More helpful error message when loading fixture with invalid date
| Reported by: | Knut Nesheim | Owned by: | Raúl Cumplido |
|---|---|---|---|
| Component: | Core (Serialization) | Version: | dev |
| Severity: | Normal | Keywords: | |
| Cc: | raulcumplido@… | Triage Stage: | Accepted |
| Has patch: | yes | Needs documentation: | no |
| Needs tests: | no | Patch needs improvement: | no |
| Easy pickings: | no | UI/UX: | no |
Description
It would be extremely helpful to have a more helpful error message when loading a fixture an invalid date. This would allow me to actually see the invalid data and I may then correct the data.
Attached is a very simple patch that will include the invalid data in the exception string. It would be extremely helpful to see more data, like the model and pk.
Attachments (3)
Change History (14)
by , 16 years ago
| Attachment: | 12467.diff added |
|---|
comment:1 by , 16 years ago
| Component: | Database layer (models, ORM) → Serialization |
|---|---|
| Needs tests: | set |
| Triage Stage: | Unreviewed → Accepted |
comment:2 by , 15 years ago
| Severity: | → Normal |
|---|---|
| Type: | → New feature |
comment:3 by , 14 years ago
| Cc: | added |
|---|---|
| Easy pickings: | unset |
| Owner: | changed from to |
| Status: | new → assigned |
| UI/UX: | unset |
comment:4 by , 14 years ago
| Needs tests: | unset |
|---|
follow-up: 6 comment:5 by , 14 years ago
The patch looks good. While we're at it, we should also do the same for DateField's "invalid_date" and DateTimeField's "invalid" messages. See amended patch attached.
by , 14 years ago
| Attachment: | 12467.2.diff added |
|---|
comment:6 by , 14 years ago
Replying to julien:
The patch looks good. While we're at it, we should also do the same for
DateField's "invalid_date" andDateTimeField's "invalid" messages. See amended patch attached.
That would be a great addition. I have one question concerning the attached patch.
How are the ValueError risen by datetime.date calls supposed to be translated? I see you're calling _(str(e)) before formating the invalid_date message but I can't find where django is supposed to catch i.e. _('month must be in 1..12') when makemessages logic is invoked.
comment:7 by , 14 years ago
That's a good question. One way would be to purposely trigger exceptions while the module is loaded to gather all the various error messages from datetime.datetime(), but that feels dirty... This is also dangerous as there's no guarantee that the messages will be the same on every version of Python.
The most complete way would be for Django to do the same tests as datetime.datetime() and then provide its own messages. However, this wouldn't be very robust and would be annoying to maintain.
Perhaps the safest way is to simply not give any granular error message and just say that it's an invalid date, as suggested in the new patch attached.
by , 14 years ago
| Attachment: | 12467.3.diff added |
|---|
comment:9 by , 14 years ago
The commit made a couple of always True asserts:
/home/akaj/Django/django_test/django/db/models/fields/__init__.py:513: SyntaxWarning: assertion is always true, perhaps remove parentheses?
assert (kwargs.get('primary_key', False) is True,
/home/akaj/Django/django_test/django/db/models/fields/__init__.py:539: SyntaxWarning: assertion is always true, perhaps remove parentheses?
comment:10 by , 14 years ago
Well spotted. This is weird, I didn't see those warnings when running the tests. I'll fix that in a minute. Thanks!
Pull Request provided here at github with tests.