Opened 11 years ago
Last modified 3 days ago
#25541 new Cleanup/optimization
Improve error reporting when loading invalid JSON fixtures
| Reported by: | awol | Owned by: | |
|---|---|---|---|
| Component: | Core (Serialization) | Version: | 1.8 |
| Severity: | Low | Keywords: | JSON fixture error |
| Cc: | VIZZARD-X | Triage Stage: | Accepted |
| Has patch: | yes | Needs documentation: | no |
| Needs tests: | no | Patch needs improvement: | no |
| Easy pickings: | no | UI/UX: | no |
Description
We load a lot of data from fixtures that we generate from a CSV based data source. The transformation from CSV to JSON for the fixture is mostly fine but from time to time as the model changes or someone adds a different instance of the CSV data set, the fixture that gets created will fail to load for one reason or another. It is very hard/impossible to know which "line" in the fixture caused the exception that prevents the whole fixture from loading.
I am not sure what the most appropriate Django like fix for this issue is, however I have found that the following change is very successful at helping me find the appropriate place in the fixture JSON file and would appreciate if something along these lines would be available in the project.
django/core/serializers/json.py 2015-10-11 22:30:32.590127937 +1100
***************
*** 82,87 ****
--- 82,88 ----
raise
except Exception as e:
# Map to deserializer error
+ e.message += " Last success '{}: {}'.".format(obj.object.__class__.__name__, obj.object)
six.reraise(DeserializationError, DeserializationError(e), sys.exc_info()[2])
Change History (6)
comment:1 by , 11 years ago
comment:2 by , 11 years ago
| Summary: | Loading JSON fixture error location reporting → Improve error reporting when loading invalid JSON fixtures |
|---|---|
| Triage Stage: | Unreviewed → Accepted |
It looks like a fixture with a nonexistent field, for example, is still difficult to debug.
comment:3 by , 4 months ago
| Owner: | changed from to |
|---|---|
| Status: | new → assigned |
comment:5 by , 3 weeks ago
| Severity: | Normal → Low |
|---|
I judge this to be a low severity issue. Me reasoning:
- It shouldn't effect typical uses of loaddata from a file generated by dumpdata for moving data or seeding dbs/tests.
- that leaves the kind of script/hand generated files which are rarer and hence lower severity
- the particular use case is coming from bad data in the csv file, a better solution could be better handled with validation on the csv, not better errors on loaddata
- I take as supporting evidence the fact this ticket has seen no activity since opened 11 years ago.
After a quick review of the open PR it seems to need a good bit of work, to me it doesn't solve the tickets issue, and would need a rethink. A better approach might be to include the model and pk values in the error message for nonexistent or missing field cases the way it is for bad value. But I still rate that low as on the main use cases for loaddata you are not likely to encounter the errors and there isn't strong evidence that many in the community are encountering such errors.
comment:6 by , 3 days ago
| Owner: | removed |
|---|---|
| Status: | assigned → new |
Some improvements were done in Django 1.9 (#19820) -- could you check how things look there for you?