From 599393172b2ff5fa85e01253d4f381111b697901 Mon Sep 17 00:00:00 2001 From: Claude Paroz Date: Sat, 16 Jul 2016 12:27:25 +0200 Subject: [PATCH] Fixed #26826 -- Stripped spaces from dumpdata pks arguments Thanks Kevin Graham Foster for the report and Tim Graham for the review. --- django/core/management/commands/dumpdata.py | 2 +- tests/fixtures/models.py | 6 ++++++ tests/fixtures/tests.py | 16 +++++++++++++++- 3 files changed, 22 insertions(+), 2 deletions(-) diff --git a/django/core/management/commands/dumpdata.py b/django/core/management/commands/dumpdata.py index e16c8f1f172..3192241a5f5 100644 --- a/django/core/management/commands/dumpdata.py +++ b/django/core/management/commands/dumpdata.py @@ -78,7 +78,7 @@ class Command(BaseCommand): pks = options['primary_keys'] if pks: - primary_keys = pks.split(',') + primary_keys = [pk.strip() for pk in pks.split(',')] else: primary_keys = [] diff --git a/tests/fixtures/models.py b/tests/fixtures/models.py index bfad34c1da8..78161c84744 100644 --- a/tests/fixtures/models.py +++ b/tests/fixtures/models.py @@ -8,6 +8,8 @@ in the application directory, or in one of the directories named in the ``FIXTURE_DIRS`` setting. """ +import uuid + from django.contrib.auth.models import Permission from django.contrib.contenttypes.fields import GenericForeignKey from django.contrib.contenttypes.models import ContentType @@ -118,3 +120,7 @@ class Book(models.Model): class Meta: ordering = ('name',) + + +class PrimaryKeyUUIDModel(models.Model): + id = models.UUIDField(primary_key=True, default=uuid.uuid4) diff --git a/tests/fixtures/tests.py b/tests/fixtures/tests.py index 95240652f33..5bff6387740 100644 --- a/tests/fixtures/tests.py +++ b/tests/fixtures/tests.py @@ -20,7 +20,9 @@ from django.test import ( from django.utils import six from django.utils.encoding import force_text -from .models import Article, Category, ProxySpy, Spy, Tag, Visa +from .models import ( + Article, Category, PrimaryKeyUUIDModel, ProxySpy, Spy, Tag, Visa, +) class TestCaseFixtureLoadingTests(TestCase): @@ -442,6 +444,18 @@ class FixtureLoadingTests(DumpDataAssertMixin, TestCase): primary_keys='2,3' ) + def test_dumpdata_with_uuid_pks(self): + m1 = PrimaryKeyUUIDModel.objects.create() + m2 = PrimaryKeyUUIDModel.objects.create() + output = six.StringIO() + management.call_command( + 'dumpdata', 'fixtures.PrimaryKeyUUIDModel', '--pks', ', '.join([str(m1.id), str(m2.id)]), + stdout=output, + ) + result = output.getvalue() + self.assertIn('"pk": "%s"' % m1.id, result) + self.assertIn('"pk": "%s"' % m2.id, result) + def test_dumpdata_with_file_output(self): management.call_command('loaddata', 'fixture1.json', verbosity=0) self._dumpdata_assert(