Opened 17 years ago
Closed 14 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 by , 17 years ago
Summary: | Object number on loaddata errors → Improve error messages in loaddata |
---|---|
Triage Stage: | Unreviewed → Accepted |
by , 17 years ago
Attachment: | 6397.patch added |
---|
comment:2 by , 17 years ago
Has patch: | set |
---|
comment:3 by , 17 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 , 17 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 , 14 years ago
Type: | → Cleanup/optimization |
---|
comment:6 by , 14 years ago
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...