Opened 8 years ago
Closed 8 years ago
#26826 closed Bug (fixed)
dumpdata command using multiple pks that are UUIDs produces error
Reported by: | TheKGF | Owned by: | Nathan Schagen |
---|---|---|---|
Component: | Core (Management commands) | Version: | 1.9 |
Severity: | Normal | Keywords: | dumpdata uuid |
Cc: | Triage Stage: | Ready for checkin | |
Has patch: | yes | Needs documentation: | no |
Needs tests: | no | Patch needs improvement: | no |
Easy pickings: | no | UI/UX: | no |
Description
For any table who's pk is a UUID object this should happen.
Model contains something like:
id = UUIDField(primary_key=True, editable=False, default=uuid.uuid4)
Run from command line:
python manage.py dumpdata foo.field --pks "2d5ae31c-c2ba-4a81-8351-35376327d33c, bc4e1ee5-1cfe-43f7-84f0-8bce347d144d"
is producing the error
CommandError: Unable to serialize database: badly formed hexadecimal UUID string
In a naive imlementation to address it, I made the following modification in dumpdata.py, although I've only really been thinking of my use case here.
[56]primary_keys = pks.split(',') for i, primary_key in enumerate(primary_keys): try: uuid_item = uuid.UUID(primary_key.strip()) primary_keys[i] = uuid_item except ValueError: pass
Change History (5)
comment:1 by , 8 years ago
Triage Stage: | Unreviewed → Accepted |
---|
comment:2 by , 8 years ago
Owner: | changed from | to
---|---|
Status: | new → assigned |
comment:3 by , 8 years ago
Has patch: | set |
---|
I found out that the problem is simply the space around the comma. While the ORM handles fine a ' 43 '
pk argument, it chokes on ' some-uuid '
.
PR.
comment:4 by , 8 years ago
Triage Stage: | Accepted → Ready for checkin |
---|
Calling
Field.to_python()
might be the way to fix that.