From 2d06c112d1b737578cd54b9193fce20d3bf10a6f Mon Sep 17 00:00:00 2001 From: Carl Meyer Date: Sat, 22 Nov 2014 22:26:58 -0700 Subject: [PATCH] Revert "[1.7.x] Fixed #23892 -- Made deconstructible classes forwards compatible" This reverts commit 8014001d9287d516c58be80ad71fb63593648b3d. Adding kwargs to deconstructed objects does not achieve useful forward-compatibility in general, since the additional kwargs are silently dropped rather than having their expected effect. In fact, it can cause the failure to be more difficult to debug. Thanks Shai Berger for discussion. --- django/core/files/storage.py | 2 +- django/core/validators.py | 6 +++--- django/db/migrations/operations/base.py | 3 --- django/db/migrations/operations/fields.py | 8 ++++---- django/db/migrations/operations/models.py | 16 ++++++++-------- django/db/migrations/operations/special.py | 6 +++--- docs/releases/1.7.2.txt | 4 ---- 7 files changed, 19 insertions(+), 26 deletions(-) diff --git a/django/core/files/storage.py b/django/core/files/storage.py index d226c6a504..8bbb1bab5c 100644 --- a/django/core/files/storage.py +++ b/django/core/files/storage.py @@ -151,7 +151,7 @@ class FileSystemStorage(Storage): """ def __init__(self, location=None, base_url=None, file_permissions_mode=None, - directory_permissions_mode=None, **kwargs): + directory_permissions_mode=None): if location is None: location = settings.MEDIA_ROOT self.base_location = location diff --git a/django/core/validators.py b/django/core/validators.py index 729198955d..1e599ec765 100644 --- a/django/core/validators.py +++ b/django/core/validators.py @@ -23,7 +23,7 @@ class RegexValidator(object): inverse_match = False flags = 0 - def __init__(self, regex=None, message=None, code=None, inverse_match=None, flags=None, **kwargs): + def __init__(self, regex=None, message=None, code=None, inverse_match=None, flags=None): if regex is not None: self.regex = regex if message is not None: @@ -132,7 +132,7 @@ class EmailValidator(object): re.IGNORECASE) domain_whitelist = ['localhost'] - def __init__(self, message=None, code=None, whitelist=None, **kwargs): + def __init__(self, message=None, code=None, whitelist=None): if message is not None: self.message = message if code is not None: @@ -236,7 +236,7 @@ class BaseValidator(object): message = _('Ensure this value is %(limit_value)s (it is %(show_value)s).') code = 'limit_value' - def __init__(self, limit_value, **kwargs): + def __init__(self, limit_value): self.limit_value = limit_value def __call__(self, value): diff --git a/django/db/migrations/operations/base.py b/django/db/migrations/operations/base.py index 8599a4856b..8d2c491add 100644 --- a/django/db/migrations/operations/base.py +++ b/django/db/migrations/operations/base.py @@ -37,9 +37,6 @@ class Operation(object): self._constructor_args = (args, kwargs) return self - def __init__(self, **kwargs): - pass - def deconstruct(self): """ Returns a 3-tuple of class import path (or just name if it lives diff --git a/django/db/migrations/operations/fields.py b/django/db/migrations/operations/fields.py index 66f82c841b..afa3fde818 100644 --- a/django/db/migrations/operations/fields.py +++ b/django/db/migrations/operations/fields.py @@ -10,7 +10,7 @@ class AddField(Operation): Adds a field to a model. """ - def __init__(self, model_name, name, field, preserve_default=True, **kwargs): + def __init__(self, model_name, name, field, preserve_default=True): self.model_name = model_name self.name = name self.field = field @@ -67,7 +67,7 @@ class RemoveField(Operation): Removes a field from a model. """ - def __init__(self, model_name, name, **kwargs): + def __init__(self, model_name, name): self.model_name = model_name self.name = name @@ -104,7 +104,7 @@ class AlterField(Operation): Alters a field's database column (e.g. null, max_length) to the provided new field """ - def __init__(self, model_name, name, field, preserve_default=True, **kwargs): + def __init__(self, model_name, name, field, preserve_default=True): self.model_name = model_name self.name = name self.field = field @@ -166,7 +166,7 @@ class RenameField(Operation): Renames a field on the model. Might affect db_column too. """ - def __init__(self, model_name, old_name, new_name, **kwargs): + def __init__(self, model_name, old_name, new_name): self.model_name = model_name self.old_name = old_name self.new_name = new_name diff --git a/django/db/migrations/operations/models.py b/django/db/migrations/operations/models.py index 423cfeed29..e195d9d841 100644 --- a/django/db/migrations/operations/models.py +++ b/django/db/migrations/operations/models.py @@ -14,7 +14,7 @@ class CreateModel(Operation): serialization_expand_args = ['fields', 'options'] - def __init__(self, name, fields, options=None, bases=None, **kwargs): + def __init__(self, name, fields, options=None, bases=None): self.name = name self.fields = fields self.options = options or {} @@ -76,7 +76,7 @@ class DeleteModel(Operation): Drops a model's table. """ - def __init__(self, name, **kwargs): + def __init__(self, name): self.name = name def state_forwards(self, app_label, state): @@ -106,7 +106,7 @@ class RenameModel(Operation): Renames a model. """ - def __init__(self, old_name, new_name, **kwargs): + def __init__(self, old_name, new_name): self.old_name = old_name self.new_name = new_name @@ -192,7 +192,7 @@ class AlterModelTable(Operation): Renames a model's table """ - def __init__(self, name, table, **kwargs): + def __init__(self, name, table): self.name = name self.table = table @@ -236,7 +236,7 @@ class AlterUniqueTogether(Operation): """ option_name = "unique_together" - def __init__(self, name, unique_together, **kwargs): + def __init__(self, name, unique_together): self.name = name unique_together = normalize_together(unique_together) self.unique_together = set(tuple(cons) for cons in unique_together) @@ -274,7 +274,7 @@ class AlterIndexTogether(Operation): """ option_name = "index_together" - def __init__(self, name, index_together, **kwargs): + def __init__(self, name, index_together): self.name = name index_together = normalize_together(index_together) self.index_together = set(tuple(cons) for cons in index_together) @@ -310,7 +310,7 @@ class AlterOrderWithRespectTo(Operation): Represents a change with the order_with_respect_to option. """ - def __init__(self, name, order_with_respect_to, **kwargs): + def __init__(self, name, order_with_respect_to): self.name = name self.order_with_respect_to = order_with_respect_to @@ -362,7 +362,7 @@ class AlterModelOptions(Operation): "verbose_name_plural", ] - def __init__(self, name, options, **kwargs): + def __init__(self, name, options): self.name = name self.options = options diff --git a/django/db/migrations/operations/special.py b/django/db/migrations/operations/special.py index 8f7be690a9..bfe418034c 100644 --- a/django/db/migrations/operations/special.py +++ b/django/db/migrations/operations/special.py @@ -11,7 +11,7 @@ class SeparateDatabaseAndState(Operation): that affect the state or not the database, or so on. """ - def __init__(self, database_operations=None, state_operations=None, **kwargs): + def __init__(self, database_operations=None, state_operations=None): self.database_operations = database_operations or [] self.state_operations = state_operations or [] @@ -50,7 +50,7 @@ class RunSQL(Operation): by this SQL change, in case it's custom column/table creation/deletion. """ - def __init__(self, sql, reverse_sql=None, state_operations=None, **kwargs): + def __init__(self, sql, reverse_sql=None, state_operations=None): self.sql = sql self.reverse_sql = reverse_sql self.state_operations = state_operations or [] @@ -86,7 +86,7 @@ class RunPython(Operation): reduces_to_sql = False - def __init__(self, code, reverse_code=None, atomic=True, **kwargs): + def __init__(self, code, reverse_code=None, atomic=True): self.atomic = atomic # Forwards code if not callable(code): diff --git a/docs/releases/1.7.2.txt b/docs/releases/1.7.2.txt index 18330dd16c..c9f69fe856 100644 --- a/docs/releases/1.7.2.txt +++ b/docs/releases/1.7.2.txt @@ -77,7 +77,3 @@ Bugfixes * Fixed a crash in migrations when deleting a field that is part of a ``index/unique_together`` constraint (:ticket:`23794`). - -* Made the initializers of deconstructible classes, such as migration - operations and validators, accept kwargs for forwards compatibility - (:ticket:`23892`).