Opened 16 years ago

Closed 13 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: dev
Severity: Normal Keywords: loaddata
Cc: Triage Stage: Accepted
Has patch: yes Needs documentation: no
Needs tests: no Patch needs improvement: yes
Easy pickings: no UI/UX: no

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

Download all attachments as: .zip

Change History (7)

comment:1 by Simon Greenhill <dev@…>, 16 years ago

Summary: Object number on loaddata errorsImprove error messages in loaddata
Triage Stage: UnreviewedAccepted

by nicklane, 16 years ago

Attachment: 6397.patch added

Quick patch from when I needed this...

comment:2 by nicklane, 16 years ago

Has patch: set

comment:3 by Russell Keith-Magee, 16 years ago

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 by anonymous, 16 years ago

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 by Julien Phalip, 13 years ago

Type: Cleanup/optimization

comment:6 by Julien Phalip, 13 years ago

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