Removed dumpdata --natural option and serializers use_natural_keys parameter.
Per deprecation timeline; refs #13252.
This commit is contained in:
parent
1d975ff44b
commit
c3336e7e4f
|
@ -1,12 +1,9 @@
|
|||
import warnings
|
||||
|
||||
from collections import OrderedDict
|
||||
|
||||
from django.apps import apps
|
||||
from django.core.management.base import BaseCommand, CommandError
|
||||
from django.core import serializers
|
||||
from django.db import router, DEFAULT_DB_ALIAS
|
||||
from django.utils.deprecation import RemovedInDjango19Warning
|
||||
|
||||
|
||||
class Command(BaseCommand):
|
||||
|
@ -28,8 +25,6 @@ class Command(BaseCommand):
|
|||
parser.add_argument('-e', '--exclude', dest='exclude', action='append', default=[],
|
||||
help='An app_label or app_label.ModelName to exclude '
|
||||
'(use multiple --exclude to exclude multiple apps/models).')
|
||||
parser.add_argument('-n', '--natural', action='store_true', dest='use_natural_keys', default=False,
|
||||
help='Use natural keys if they are available (deprecated: use --natural-foreign instead).')
|
||||
parser.add_argument('--natural-foreign', action='store_true', dest='use_natural_foreign_keys', default=False,
|
||||
help='Use natural foreign keys if they are available.')
|
||||
parser.add_argument('--natural-primary', action='store_true', dest='use_natural_primary_keys', default=False,
|
||||
|
@ -51,11 +46,7 @@ class Command(BaseCommand):
|
|||
excludes = options.get('exclude')
|
||||
output = options.get('output')
|
||||
show_traceback = options.get('traceback')
|
||||
use_natural_keys = options.get('use_natural_keys')
|
||||
if use_natural_keys:
|
||||
warnings.warn("``--natural`` is deprecated; use ``--natural-foreign`` instead.",
|
||||
RemovedInDjango19Warning)
|
||||
use_natural_foreign_keys = options.get('use_natural_foreign_keys') or use_natural_keys
|
||||
use_natural_foreign_keys = options.get('use_natural_foreign_keys')
|
||||
use_natural_primary_keys = options.get('use_natural_primary_keys')
|
||||
use_base_manager = options.get('use_base_manager')
|
||||
pks = options.get('primary_keys')
|
||||
|
|
|
@ -1,11 +1,8 @@
|
|||
"""
|
||||
Module for abstract serializer/unserializer base classes.
|
||||
"""
|
||||
import warnings
|
||||
|
||||
from django.db import models
|
||||
from django.utils import six
|
||||
from django.utils.deprecation import RemovedInDjango19Warning
|
||||
|
||||
|
||||
class SerializerDoesNotExist(KeyError):
|
||||
|
@ -40,11 +37,7 @@ class Serializer(object):
|
|||
|
||||
self.stream = options.pop("stream", six.StringIO())
|
||||
self.selected_fields = options.pop("fields", None)
|
||||
self.use_natural_keys = options.pop("use_natural_keys", False)
|
||||
if self.use_natural_keys:
|
||||
warnings.warn("``use_natural_keys`` is deprecated; use ``use_natural_foreign_keys`` instead.",
|
||||
RemovedInDjango19Warning)
|
||||
self.use_natural_foreign_keys = options.pop('use_natural_foreign_keys', False) or self.use_natural_keys
|
||||
self.use_natural_foreign_keys = options.pop('use_natural_foreign_keys', False)
|
||||
self.use_natural_primary_keys = options.pop('use_natural_primary_keys', False)
|
||||
|
||||
self.start_serialization()
|
||||
|
|
|
@ -304,15 +304,6 @@ When this option is specified, Django will not provide the primary key in the
|
|||
serialized data of this object since it can be calculated during
|
||||
deserialization.
|
||||
|
||||
.. django-admin-option:: --natural
|
||||
|
||||
.. deprecated:: 1.7
|
||||
Equivalent to the :djadminopt:`--natural-foreign` option; use that instead.
|
||||
|
||||
Use :ref:`natural keys <topics-serialization-natural-keys>` to represent
|
||||
any foreign key and many-to-many relationship with a model that provides
|
||||
a natural key definition.
|
||||
|
||||
.. django-admin-option:: --pks
|
||||
|
||||
By default, ``dumpdata`` will output all the records of the model, but
|
||||
|
|
|
@ -479,19 +479,6 @@ line flags to generate natural keys.
|
|||
natural keys during serialization, but *not* be able to load those
|
||||
key values, just don't define the ``get_by_natural_key()`` method.
|
||||
|
||||
.. versionchanged:: 1.7
|
||||
|
||||
Previously there was only a ``use_natural_keys`` argument for
|
||||
``serializers.serialize()`` and the `-n` or `--natural` command line flags.
|
||||
These have been deprecated in favor of the ``use_natural_foreign_keys`` and
|
||||
``use_natural_primary_keys`` arguments and the corresponding
|
||||
:djadminopt:`--natural-foreign` and :djadminopt:`--natural-primary` options
|
||||
for :djadmin:`dumpdata`.
|
||||
|
||||
The original argument and command line flags remain for backwards
|
||||
compatibility and map to the new ``use_natural_foreign_keys`` argument and
|
||||
`--natural-foreign` command line flag. They'll be removed in Django 1.9.
|
||||
|
||||
Dependencies during serialization
|
||||
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
|
||||
|
|
|
@ -23,9 +23,8 @@ from django.core.serializers.base import DeserializationError
|
|||
from django.core.serializers.xml_serializer import DTDForbidden
|
||||
from django.db import connection, models
|
||||
from django.http import HttpResponse
|
||||
from django.test import ignore_warnings, skipUnlessDBFeature, TestCase
|
||||
from django.test import skipUnlessDBFeature, TestCase
|
||||
from django.utils import six
|
||||
from django.utils.deprecation import RemovedInDjango19Warning
|
||||
from django.utils.functional import curry
|
||||
|
||||
from .models import (BinaryData, BooleanData, CharData, DateData, DateTimeData, EmailData,
|
||||
|
@ -483,7 +482,6 @@ def serializerTest(format, self):
|
|||
self.assertEqual(count, klass.objects.count())
|
||||
|
||||
|
||||
@ignore_warnings(category=RemovedInDjango19Warning) # for use_natural_keys
|
||||
def naturalKeySerializerTest(format, self):
|
||||
# Create all the objects defined in the test data
|
||||
objects = []
|
||||
|
@ -496,10 +494,9 @@ def naturalKeySerializerTest(format, self):
|
|||
for klass in instance_count:
|
||||
instance_count[klass] = klass.objects.count()
|
||||
|
||||
# use_natural_keys is deprecated and to be removed in Django 1.9
|
||||
# Serialize the test database
|
||||
serialized_data = serializers.serialize(format, objects, indent=2,
|
||||
use_natural_keys=True)
|
||||
use_natural_foreign_keys=True)
|
||||
|
||||
for obj in serializers.deserialize(format, serialized_data):
|
||||
obj.save()
|
||||
|
|
Loading…
Reference in New Issue