Opened 15 years ago
Closed 11 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)
Change History (7)
comment:1 Changed 15 years ago by
Summary: | Object number on loaddata errors → Improve error messages in loaddata |
---|---|
Triage Stage: | Unreviewed → Accepted |
Changed 15 years ago by
Attachment: | 6397.patch added |
---|
comment:2 Changed 15 years ago by
Has patch: | set |
---|
comment:3 Changed 14 years ago by
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 14 years ago by
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 11 years ago by
Type: | → Cleanup/optimization |
---|
comment:6 Changed 11 years ago by
Resolution: | → duplicate |
---|---|
Severity: | → Normal |
Status: | new → closed |
I'm going to close this as a dupe of #10200 which, although newer, has a more comprehensive discussion and patch.
Quick patch from when I needed this...