Opened 9 years ago
Last modified 9 years ago
#25541 new Cleanup/optimization
Improve error reporting when loading invalid JSON fixtures
Reported by: | awol | Owned by: | nobody |
---|---|---|---|
Component: | Core (Serialization) | Version: | 1.8 |
Severity: | Normal | Keywords: | JSON fixture error |
Cc: | Triage Stage: | Accepted | |
Has patch: | no | 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 (2)
comment:1 by , 9 years ago
comment:2 by , 9 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.
Some improvements were done in Django 1.9 (#19820) -- could you check how things look there for you?