Opened 7 years ago

Closed 4 years ago

#6397 closed Cleanup/optimization (duplicate)

Improve error messages in loaddata

Reported by: Ariel <ingenieroariel a..t gmail d..o..t com> Owned by: nobody
Component: Core (Serialization) Version: master
Severity: Normal Keywords: loaddata
Cc: Triage Stage: Accepted
Has patch: yes Needs documentation: no
Needs tests: no Patch needs improvement: yes
Easy pickings: UI/UX:

Description

When trying to load some fixtures I encountered a

"Problem installing fixture 'mydata.json': duplicate key violates unique constraint "unique_for_data".

I know what the problem is, but I don't know where to start looking. A best approach could be:

"Problem installing fixture 'mydata.json' (object: 27): duplicate key violates unique constraint "unique_for_data".

On django/core/managment/commands/loaddata.py - line 103
The number of loaded objects is already stored on count[0] so it would only be a matter of adding it to the error string.

Attachments (1)

6397.patch (877 bytes) - added by nicklane 7 years ago.
Quick patch from when I needed this…

Download all attachments as: .zip

Change History (7)

comment:1 Changed 7 years ago by Simon Greenhill <dev@…>

  • Needs documentation unset
  • Needs tests unset
  • Patch needs improvement unset
  • Summary changed from Object number on loaddata errors to Improve error messages in loaddata
  • Triage Stage changed from Unreviewed to Accepted

Changed 7 years ago by nicklane

Quick patch from when I needed this...

comment:2 Changed 7 years ago by nicklane

  • Has patch set

comment:3 Changed 7 years ago by russellm

  • Patch needs improvement set

The broader issue - improving error messages - is certainly worthwhile. However, I'm not sure that this specific suggestion is the best we can do. count[0] isn't a useful count, since it is an overall count including all previously loaded fixtures. A more useful value would be to dump the object ID and model name. However, this will be much harder to achieve.

comment:4 Changed 7 years ago by anonymous

The best info would imo be the line number, plus some object information (object id at least). For this to work, the serializer must store the line number in the generated objects while reading serialized data. The error message then could look like:

mydata.json: 107: error installing fixture object #27: duplicate key violates unique constraint "unique_for_data"

comment:5 Changed 4 years ago by julien

  • Type set to Cleanup/optimization

comment:6 Changed 4 years ago by julien

  • Resolution set to duplicate
  • Severity set to Normal
  • Status changed from new to closed

I'm going to close this as a dupe of #10200 which, although newer, has a more comprehensive discussion and patch.

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