Opened 3 years ago

Last modified 3 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 Changed 3 years ago by Tim Graham

Some improvements were done in Django 1.9 (#19820) -- could you check how things look there for you?

comment:2 Changed 3 years ago by Tim Graham

Summary: Loading JSON fixture error location reportingImprove error reporting when loading invalid JSON fixtures
Triage Stage: UnreviewedAccepted

It looks like a fixture with a nonexistent field, for example, is still difficult to debug.

Note: See TracTickets for help on using tickets.
Back to Top