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 Tim Graham, 8 years ago

Triage Stage: UnreviewedAccepted

Calling Field.to_python() might be the way to fix that.

comment:2 by Nathan Schagen, 8 years ago

Owner: changed from nobody to Nathan Schagen
Status: newassigned

comment:3 by Claude Paroz, 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 Tim Graham, 8 years ago

Triage Stage: AcceptedReady for checkin

comment:5 by Claude Paroz <claude@…>, 8 years ago

Resolution: fixed
Status: assignedclosed

In 59939317:

Fixed #26826 -- Stripped spaces from dumpdata pks arguments

Thanks Kevin Graham Foster for the report and Tim Graham for the review.

Note: See TracTickets for help on using tickets.
Back to Top