Opened 9 years ago

Closed 5 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:


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/ - 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 9 years ago.
Quick patch from when I needed this…

Download all attachments as: .zip

Change History (7)

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

Needs documentation: unset
Needs tests: unset
Patch needs improvement: unset
Summary: Object number on loaddata errorsImprove error messages in loaddata
Triage Stage: UnreviewedAccepted

Changed 9 years ago by nicklane

Attachment: 6397.patch added

Quick patch from when I needed this...

comment:2 Changed 9 years ago by nicklane

Has patch: set

comment:3 Changed 9 years ago by Russell Keith-Magee

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 9 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 6 years ago by Julien Phalip

Type: Cleanup/optimization

comment:6 Changed 5 years ago by Julien Phalip

Resolution: duplicate
Severity: Normal
Status: newclosed

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