Parcourir la source

Removed unnecessary parentheses in model check messages.

Tim Graham il y a 10 ans
Parent
commit
e144e0e237
2 fichiers modifiés avec 50 ajouts et 45 suppressions
  1. 20 16
      django/db/models/base.py
  2. 30 29
      tests/invalid_models_tests/test_models.py

+ 20 - 16
django/db/models/base.py

@@ -1206,7 +1206,8 @@ class Model(six.with_metaclass(ModelBase)):
                 app_label, model_name = cls._meta.swapped.split('.')
                 errors.append(
                     checks.Error(
-                        ("'%s' references '%s.%s', which has not been installed, or is abstract.") % (
+                        "'%s' references '%s.%s', which has not been "
+                        "installed, or is abstract." % (
                             cls._meta.swappable, app_label, model_name
                         ),
                         hint=None,
@@ -1272,8 +1273,8 @@ class Model(six.with_metaclass(ModelBase)):
             if signature in seen_intermediary_signatures:
                 errors.append(
                     checks.Error(
-                        ("The model has two many-to-many relations through "
-                         "the intermediate model '%s.%s'.") % (
+                        "The model has two many-to-many relations through "
+                        "the intermediate model '%s.%s'." % (
                             f.rel.through._meta.app_label,
                             f.rel.through._meta.object_name
                         ),
@@ -1296,8 +1297,8 @@ class Model(six.with_metaclass(ModelBase)):
         if fields and not fields[0].primary_key and cls._meta.pk.name == 'id':
             return [
                 checks.Error(
-                    ("'id' can only be used as a field name if the field also "
-                     "sets 'primary_key=True'."),
+                    "'id' can only be used as a field name if the field also "
+                    "sets 'primary_key=True'.",
                     hint=None,
                     obj=cls,
                     id='models.E004',
@@ -1320,9 +1321,9 @@ class Model(six.with_metaclass(ModelBase)):
                 if clash:
                     errors.append(
                         checks.Error(
-                            ("The field '%s' from parent model "
-                             "'%s' clashes with the field '%s' "
-                             "from parent model '%s'.") % (
+                            "The field '%s' from parent model "
+                            "'%s' clashes with the field '%s' "
+                            "from parent model '%s'." % (
                                 clash.name, clash.model._meta,
                                 f.name, f.model._meta
                             ),
@@ -1347,8 +1348,8 @@ class Model(six.with_metaclass(ModelBase)):
             if clash and not id_conflict:
                 errors.append(
                     checks.Error(
-                        ("The field '%s' clashes with the field '%s' "
-                         "from model '%s'.") % (
+                        "The field '%s' clashes with the field '%s' "
+                        "from model '%s'." % (
                             f.name, clash.name, clash.model._meta
                         ),
                         hint=None,
@@ -1374,7 +1375,8 @@ class Model(six.with_metaclass(ModelBase)):
             if column_name and column_name in used_column_names:
                 errors.append(
                     checks.Error(
-                        "Field '%s' has column name '%s' that is used by another field." % (f.name, column_name),
+                        "Field '%s' has column name '%s' that is used by "
+                        "another field." % (f.name, column_name),
                         hint="Specify a 'db_column' for the field.",
                         obj=cls,
                         id='models.E007'
@@ -1462,7 +1464,9 @@ class Model(six.with_metaclass(ModelBase)):
             except KeyError:
                 errors.append(
                     checks.Error(
-                        "'%s' refers to the non-existent field '%s'." % (option, field_name),
+                        "'%s' refers to the non-existent field '%s'." % (
+                            option, field_name,
+                        ),
                         hint=None,
                         obj=cls,
                         id='models.E012',
@@ -1472,9 +1476,9 @@ class Model(six.with_metaclass(ModelBase)):
                 if isinstance(field.rel, models.ManyToManyRel):
                     errors.append(
                         checks.Error(
-                            ("'%s' refers to a ManyToManyField '%s', but "
-                             "ManyToManyFields are not permitted in '%s'.") % (
-                                option, field_name, option
+                            "'%s' refers to a ManyToManyField '%s', but "
+                            "ManyToManyFields are not permitted in '%s'." % (
+                                option, field_name, option,
                             ),
                             hint=None,
                             obj=cls,
@@ -1486,7 +1490,7 @@ class Model(six.with_metaclass(ModelBase)):
                         checks.Error(
                             ("'%s' refers to field '%s' which is not local "
                              "to model '%s'.") % (
-                                option, field_name, cls._meta.object_name
+                                option, field_name, cls._meta.object_name,
                             ),
                             hint=("This issue may be caused by multi-table "
                                   "inheritance."),

+ 30 - 29
tests/invalid_models_tests/test_models.py

@@ -114,8 +114,8 @@ class IndexTogetherTests(IsolatedModelsTestCase):
         errors = Bar.check()
         expected = [
             Error(
-                ("'index_together' refers to field 'field1' which is not "
-                 "local to model 'Bar'."),
+                "'index_together' refers to field 'field1' which is not "
+                "local to model 'Bar'.",
                 hint=("This issue may be caused by multi-table inheritance."),
                 obj=Bar,
                 id='models.E016',
@@ -135,8 +135,8 @@ class IndexTogetherTests(IsolatedModelsTestCase):
         errors = Model.check()
         expected = [
             Error(
-                ("'index_together' refers to a ManyToManyField 'm2m', but "
-                 "ManyToManyFields are not permitted in 'index_together'."),
+                "'index_together' refers to a ManyToManyField 'm2m', but "
+                "ManyToManyFields are not permitted in 'index_together'.",
                 hint=None,
                 obj=Model,
                 id='models.E013',
@@ -241,8 +241,8 @@ class UniqueTogetherTests(IsolatedModelsTestCase):
         errors = Model.check()
         expected = [
             Error(
-                ("'unique_together' refers to a ManyToManyField 'm2m', but "
-                 "ManyToManyFields are not permitted in 'unique_together'."),
+                "'unique_together' refers to a ManyToManyField 'm2m', but "
+                "ManyToManyFields are not permitted in 'unique_together'.",
                 hint=None,
                 obj=Model,
                 id='models.E013',
@@ -330,9 +330,9 @@ class FieldNamesTests(IsolatedModelsTestCase):
         m2m_long_name = "verylongmodelnamezzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz_id"
         expected = [
             Error(
-                ('Autogenerated column name too long for M2M field "%s". '
+                'Autogenerated column name too long for M2M field "%s". '
                 'Maximum length is "%s" for database "%s".'
-                % (m2m_long_name, self.max_column_name_length, self.column_limit_db_alias)),
+                % (m2m_long_name, self.max_column_name_length, self.column_limit_db_alias),
                 hint=("Use 'through' to create a separate model for "
                     "M2M and then set column_name using 'db_column'."),
                 obj=ModelWithLongField,
@@ -347,9 +347,9 @@ class FieldNamesTests(IsolatedModelsTestCase):
         # name is longer than the limits of the database.
         expected.append(
             Error(
-                ('Autogenerated column name too long for M2M field "%s_id". '
+                'Autogenerated column name too long for M2M field "%s_id". '
                 'Maximum length is "%s" for database "%s".'
-                % (long_field_name, self.max_column_name_length, self.column_limit_db_alias)),
+                % (long_field_name, self.max_column_name_length, self.column_limit_db_alias),
                 hint=("Use 'through' to create a separate model for "
                     "M2M and then set column_name using 'db_column'."),
                 obj=ModelWithLongField,
@@ -382,9 +382,9 @@ class FieldNamesTests(IsolatedModelsTestCase):
         # without specifying db_column
         expected = [
             Error(
-                ('Autogenerated column name too long for field "%s". '
+                'Autogenerated column name too long for field "%s". '
                 'Maximum length is "%s" for database "%s".'
-                % (long_field_name, self.max_column_name_length, self.column_limit_db_alias)),
+                % (long_field_name, self.max_column_name_length, self.column_limit_db_alias),
                 hint="Set the column name manually using 'db_column'.",
                 obj=ModelWithLongField,
                 id='models.E018',
@@ -441,17 +441,17 @@ class ShadowingFieldsTests(IsolatedModelsTestCase):
         errors = Child.check()
         expected = [
             Error(
-                ("The field 'id' from parent model "
-                 "'invalid_models_tests.mother' clashes with the field 'id' "
-                 "from parent model 'invalid_models_tests.father'."),
+                "The field 'id' from parent model "
+                "'invalid_models_tests.mother' clashes with the field 'id' "
+                "from parent model 'invalid_models_tests.father'.",
                 hint=None,
                 obj=Child,
                 id='models.E005',
             ),
             Error(
-                ("The field 'clash' from parent model "
-                 "'invalid_models_tests.mother' clashes with the field 'clash' "
-                 "from parent model 'invalid_models_tests.father'."),
+                "The field 'clash' from parent model "
+                "'invalid_models_tests.mother' clashes with the field 'clash' "
+                "from parent model 'invalid_models_tests.father'.",
                 hint=None,
                 obj=Child,
                 id='models.E005',
@@ -474,8 +474,8 @@ class ShadowingFieldsTests(IsolatedModelsTestCase):
         errors = Child.check()
         expected = [
             Error(
-                ("The field 'f' clashes with the field 'f_id' "
-                 "from model 'invalid_models_tests.parent'."),
+                "The field 'f' clashes with the field 'f_id' "
+                "from model 'invalid_models_tests.parent'.",
                 hint=None,
                 obj=Child._meta.get_field('f'),
                 id='models.E006',
@@ -519,8 +519,8 @@ class ShadowingFieldsTests(IsolatedModelsTestCase):
         errors = Model.check()
         expected = [
             Error(
-                ("The field 'fk_id' clashes with the field 'fk' from model "
-                 "'invalid_models_tests.model'."),
+                "The field 'fk_id' clashes with the field 'fk' from model "
+                "'invalid_models_tests.model'.",
                 hint=None,
                 obj=Model._meta.get_field('fk_id'),
                 id='models.E006',
@@ -540,7 +540,8 @@ class OtherModelTests(IsolatedModelsTestCase):
         errors = Model.check()
         expected = [
             Error(
-                "'id' can only be used as a field name if the field also sets 'primary_key=True'.",
+                "'id' can only be used as a field name if the field also sets "
+                "'primary_key=True'.",
                 hint=None,
                 obj=Model,
                 id='models.E004',
@@ -556,8 +557,8 @@ class OtherModelTests(IsolatedModelsTestCase):
         errors = Model.check()
         expected = [
             Error(
-                ("'ordering' must be a tuple or list "
-                 "(even if you want to order by only one field)."),
+                "'ordering' must be a tuple or list "
+                "(even if you want to order by only one field).",
                 hint=None,
                 obj=Model,
                 id='models.E014',
@@ -662,8 +663,8 @@ class OtherModelTests(IsolatedModelsTestCase):
         errors = Model.check()
         expected = [
             Error(
-                ("'TEST_SWAPPED_MODEL_BAD_MODEL' references 'not_an_app.Target', "
-                 'which has not been installed, or is abstract.'),
+                "'TEST_SWAPPED_MODEL_BAD_MODEL' references 'not_an_app.Target', "
+                'which has not been installed, or is abstract.',
                 hint=None,
                 obj=None,
                 id='models.E002',
@@ -688,8 +689,8 @@ class OtherModelTests(IsolatedModelsTestCase):
         errors = Group.check()
         expected = [
             Error(
-                ("The model has two many-to-many relations through "
-                 "the intermediate model 'invalid_models_tests.Membership'."),
+                "The model has two many-to-many relations through "
+                "the intermediate model 'invalid_models_tests.Membership'.",
                 hint=None,
                 obj=Group,
                 id='models.E003',