Removed unneeded hint=None/obj=None in system check messages.

This commit is contained in:
Tim Graham 2016-02-12 11:36:46 -05:00
parent 36f1f5cfb0
commit 004ba0f99e
30 changed files with 287 additions and 495 deletions

View File

@ -123,7 +123,6 @@ class BaseModelAdminChecks(object):
return [
checks.Error(
"Both 'fieldsets' and 'fields' are specified.",
hint=None,
obj=obj.__class__,
id='admin.E005',
)
@ -133,7 +132,6 @@ class BaseModelAdminChecks(object):
return [
checks.Error(
"The value of 'fields' contains duplicate field(s).",
hint=None,
obj=obj.__class__,
id='admin.E006',
)
@ -172,7 +170,6 @@ class BaseModelAdminChecks(object):
return [
checks.Error(
"The value of '%s[1]' must contain the key 'fields'." % label,
hint=None,
obj=obj.__class__,
id='admin.E011',
)
@ -185,7 +182,6 @@ class BaseModelAdminChecks(object):
return [
checks.Error(
"There are duplicate field(s) in '%s[1]'." % label,
hint=None,
obj=obj.__class__,
id='admin.E012',
)
@ -226,10 +222,9 @@ class BaseModelAdminChecks(object):
not field.remote_field.through._meta.auto_created):
return [
checks.Error(
("The value of '%s' cannot include the ManyToManyField '%s', "
"because that field manually specifies a relationship model.")
"The value of '%s' cannot include the ManyToManyField '%s', "
"because that field manually specifies a relationship model."
% (label, field_name),
hint=None,
obj=obj.__class__,
id='admin.E013',
)
@ -248,7 +243,6 @@ class BaseModelAdminChecks(object):
return [
checks.Error(
"The value of 'exclude' contains duplicate field(s).",
hint=None,
obj=obj.__class__,
id='admin.E015',
)
@ -337,7 +331,6 @@ class BaseModelAdminChecks(object):
"instance of ForeignKey, and does not have a 'choices' definition." % (
label, field_name
),
hint=None,
obj=obj.__class__,
id='admin.E023',
)
@ -354,7 +347,6 @@ class BaseModelAdminChecks(object):
return [
checks.Error(
"The value of '%s' must be either admin.HORIZONTAL or admin.VERTICAL." % label,
hint=None,
obj=obj.__class__,
id='admin.E024',
)
@ -368,7 +360,6 @@ class BaseModelAdminChecks(object):
return [
checks.Error(
"The value of 'view_on_site' must be a callable or a boolean value.",
hint=None,
obj=obj.__class__,
id='admin.E025',
)
@ -414,10 +405,7 @@ class BaseModelAdminChecks(object):
return [
checks.Error(
"The value of '%s' refers to '%s', which must not be a DateTimeField, "
"ForeignKey or ManyToManyField." % (
label, field_name
),
hint=None,
"ForeignKey or ManyToManyField." % (label, field_name),
obj=obj.__class__,
id='admin.E028',
)
@ -444,8 +432,7 @@ class BaseModelAdminChecks(object):
try:
model._meta.get_field(field_name)
except FieldDoesNotExist:
return refer_to_missing_field(field=field_name, option=label,
model=model, obj=obj, id='admin.E030')
return refer_to_missing_field(field=field_name, option=label, model=model, obj=obj, id='admin.E030')
else:
return []
@ -469,8 +456,8 @@ class BaseModelAdminChecks(object):
if field_name == '?' and len(obj.ordering) != 1:
return [
checks.Error(
("The value of 'ordering' has the random ordering marker '?', "
"but contains other fields as well."),
"The value of 'ordering' has the random ordering marker '?', "
"but contains other fields as well.",
hint='Either remove the "?", or remove the other fields.',
obj=obj.__class__,
id='admin.E032',
@ -489,8 +476,7 @@ class BaseModelAdminChecks(object):
try:
model._meta.get_field(field_name)
except FieldDoesNotExist:
return refer_to_missing_field(field=field_name, option=label,
model=model, obj=obj, id='admin.E033')
return refer_to_missing_field(field=field_name, option=label, model=model, obj=obj, id='admin.E033')
else:
return []
@ -523,7 +509,6 @@ class BaseModelAdminChecks(object):
"The value of '%s' is not a callable, an attribute of '%s', or an attribute of '%s.%s'." % (
label, obj.__class__.__name__, model._meta.app_label, model._meta.object_name
),
hint=None,
obj=obj.__class__,
id='admin.E035',
)
@ -589,7 +574,6 @@ class ModelAdminChecks(BaseModelAdminChecks):
return [
checks.Error(
"'%s' must inherit from 'BaseModelAdmin'." % inline_label,
hint=None,
obj=obj.__class__,
id='admin.E104',
)
@ -598,14 +582,12 @@ class ModelAdminChecks(BaseModelAdminChecks):
return [
checks.Error(
"'%s' must have a 'model' attribute." % inline_label,
hint=None,
obj=obj.__class__,
id='admin.E105',
)
]
elif not issubclass(inline.model, models.Model):
return must_be('a Model', option='%s.model' % inline_label,
obj=obj, id='admin.E106')
return must_be('a Model', option='%s.model' % inline_label, obj=obj, id='admin.E106')
else:
return inline(model, obj.admin_site).check()
@ -643,7 +625,6 @@ class ModelAdminChecks(BaseModelAdminChecks):
"callable, an attribute of '%s', or an attribute or method on '%s.%s'." % (
label, item, obj.__class__.__name__, model._meta.app_label, model._meta.object_name
),
hint=None,
obj=obj.__class__,
id='admin.E108',
)
@ -652,7 +633,6 @@ class ModelAdminChecks(BaseModelAdminChecks):
return [
checks.Error(
"The value of '%s' must not be a ManyToManyField." % label,
hint=None,
obj=obj.__class__,
id='admin.E109',
)
@ -671,7 +651,6 @@ class ModelAdminChecks(BaseModelAdminChecks):
"an attribute of '%s', or an attribute or method on '%s.%s'." % (
label, item, obj.__class__.__name__, model._meta.app_label, model._meta.object_name
),
hint=None,
obj=obj.__class__,
id='admin.E108',
)
@ -700,7 +679,6 @@ class ModelAdminChecks(BaseModelAdminChecks):
"The value of '%s' refers to '%s', which is not defined in 'list_display'." % (
label, field_name
),
hint=None,
obj=obj.__class__,
id='admin.E111',
)
@ -738,7 +716,6 @@ class ModelAdminChecks(BaseModelAdminChecks):
return [
checks.Error(
"The value of '%s' must not inherit from 'FieldListFilter'." % label,
hint=None,
obj=obj.__class__,
id='admin.E114',
)
@ -749,8 +726,7 @@ class ModelAdminChecks(BaseModelAdminChecks):
# item is option #2
field, list_filter_class = item
if not issubclass(list_filter_class, FieldListFilter):
return must_inherit_from(parent='FieldListFilter', option='%s[1]' % label,
obj=obj, id='admin.E115')
return must_inherit_from(parent='FieldListFilter', option='%s[1]' % label, obj=obj, id='admin.E115')
else:
return []
else:
@ -764,7 +740,6 @@ class ModelAdminChecks(BaseModelAdminChecks):
return [
checks.Error(
"The value of '%s' refers to '%s', which does not refer to a Field." % (label, field),
hint=None,
obj=obj.__class__,
id='admin.E116',
)
@ -776,8 +751,7 @@ class ModelAdminChecks(BaseModelAdminChecks):
""" Check that list_select_related is a boolean, a list or a tuple. """
if not isinstance(obj.list_select_related, (bool, list, tuple)):
return must_be('a boolean, tuple or list', option='list_select_related',
obj=obj, id='admin.E117')
return must_be('a boolean, tuple or list', option='list_select_related', obj=obj, id='admin.E117')
else:
return []
@ -813,15 +787,13 @@ class ModelAdminChecks(BaseModelAdminChecks):
try:
field = model._meta.get_field(field_name)
except FieldDoesNotExist:
return refer_to_missing_field(field=field_name, option=label,
model=model, obj=obj, id='admin.E121')
return refer_to_missing_field(field=field_name, option=label, model=model, obj=obj, id='admin.E121')
else:
if field_name not in obj.list_display:
return [
checks.Error(
"The value of '%s' refers to '%s', which is not "
"contained in 'list_display'." % (label, field_name),
hint=None,
obj=obj.__class__,
id='admin.E122',
)
@ -830,7 +802,6 @@ class ModelAdminChecks(BaseModelAdminChecks):
return [
checks.Error(
"The value of '%s' cannot be in both 'list_editable' and 'list_display_links'." % field_name,
hint=None,
obj=obj.__class__,
id='admin.E123',
)
@ -845,7 +816,6 @@ class ModelAdminChecks(BaseModelAdminChecks):
"which cannot be used unless 'list_display_links' is set." % (
label, obj.list_display[0]
),
hint=None,
obj=obj.__class__,
id='admin.E124',
)
@ -856,7 +826,6 @@ class ModelAdminChecks(BaseModelAdminChecks):
"The value of '%s' refers to '%s', which is not editable through the admin." % (
label, field_name
),
hint=None,
obj=obj.__class__,
id='admin.E125',
)
@ -881,13 +850,13 @@ class ModelAdminChecks(BaseModelAdminChecks):
try:
field = obj.model._meta.get_field(obj.date_hierarchy)
except FieldDoesNotExist:
return refer_to_missing_field(option='date_hierarchy',
field=obj.date_hierarchy,
model=obj.model, obj=obj, id='admin.E127')
return refer_to_missing_field(
option='date_hierarchy', field=obj.date_hierarchy,
model=obj.model, obj=obj, id='admin.E127',
)
else:
if not isinstance(field, (models.DateField, models.DateTimeField)):
return must_be('a DateField or DateTimeField', option='date_hierarchy',
obj=obj, id='admin.E128')
return must_be('a DateField or DateTimeField', option='date_hierarchy', obj=obj, id='admin.E128')
else:
return []
@ -927,7 +896,6 @@ class InlineModelAdminChecks(BaseModelAdminChecks):
"to the parent model '%s.%s'." % (
fk.name, parent_model._meta.app_label, parent_model._meta.object_name
),
hint=None,
obj=obj.__class__,
id='admin.E201',
)
@ -939,7 +907,7 @@ class InlineModelAdminChecks(BaseModelAdminChecks):
try:
_get_foreign_key(parent_model, obj.model, fk_name=obj.fk_name)
except ValueError as e:
return [checks.Error(e.args[0], hint=None, obj=obj.__class__, id='admin.E202')]
return [checks.Error(e.args[0], obj=obj.__class__, id='admin.E202')]
else:
return []
@ -975,8 +943,7 @@ class InlineModelAdminChecks(BaseModelAdminChecks):
""" Check formset is a subclass of BaseModelFormSet. """
if not issubclass(obj.formset, BaseModelFormSet):
return must_inherit_from(parent='BaseModelFormSet', option='formset',
obj=obj, id='admin.E206')
return must_inherit_from(parent='BaseModelFormSet', option='formset', obj=obj, id='admin.E206')
else:
return []
@ -985,7 +952,6 @@ def must_be(type, option, obj, id):
return [
checks.Error(
"The value of '%s' must be %s." % (option, type),
hint=None,
obj=obj.__class__,
id=id,
),
@ -996,7 +962,6 @@ def must_inherit_from(parent, option, obj, id):
return [
checks.Error(
"The value of '%s' must inherit from '%s'." % (option, parent),
hint=None,
obj=obj.__class__,
id=id,
),
@ -1009,7 +974,6 @@ def refer_to_missing_field(field, option, model, obj, id):
"The value of '%s' refers to '%s', which is not an attribute of '%s.%s'." % (
option, field, model._meta.app_label, model._meta.object_name
),
hint=None,
obj=obj.__class__,
id=id,
),

View File

@ -28,7 +28,6 @@ def check_user_model(app_configs=None, **kwargs):
errors.append(
checks.Error(
"'REQUIRED_FIELDS' must be a list or tuple.",
hint=None,
obj=cls,
id='auth.E001',
)
@ -38,9 +37,8 @@ def check_user_model(app_configs=None, **kwargs):
if cls.USERNAME_FIELD in cls.REQUIRED_FIELDS:
errors.append(
checks.Error(
("The field named as the 'USERNAME_FIELD' "
"for a custom user model must not be included in 'REQUIRED_FIELDS'."),
hint=None,
"The field named as the 'USERNAME_FIELD' "
"for a custom user model must not be included in 'REQUIRED_FIELDS'.",
obj=cls,
id='auth.E002',
)
@ -55,7 +53,6 @@ def check_user_model(app_configs=None, **kwargs):
"'%s.%s' must be unique because it is named as the 'USERNAME_FIELD'." % (
cls._meta.object_name, cls.USERNAME_FIELD
),
hint=None,
obj=cls,
id='auth.E003',
)
@ -66,8 +63,7 @@ def check_user_model(app_configs=None, **kwargs):
"'%s.%s' is named as the 'USERNAME_FIELD', but it is not unique." % (
cls._meta.object_name, cls.USERNAME_FIELD
),
hint=('Ensure that your authentication backend(s) can handle '
'non-unique usernames.'),
hint='Ensure that your authentication backend(s) can handle non-unique usernames.',
obj=cls,
id='auth.W004',
)

View File

@ -33,7 +33,6 @@ class GenericInlineModelAdminChecks(InlineModelAdminChecks):
"'%s.%s' has no GenericForeignKey." % (
obj.model._meta.app_label, obj.model._meta.object_name
),
hint=None,
obj=obj.__class__,
id='admin.E301'
)
@ -48,7 +47,6 @@ class GenericInlineModelAdminChecks(InlineModelAdminChecks):
"'ct_field' references '%s', which is not a field on '%s.%s'." % (
obj.ct_field, obj.model._meta.app_label, obj.model._meta.object_name
),
hint=None,
obj=obj.__class__,
id='admin.E302'
)
@ -62,7 +60,6 @@ class GenericInlineModelAdminChecks(InlineModelAdminChecks):
"'ct_fk_field' references '%s', which is not a field on '%s.%s'." % (
obj.ct_fk_field, obj.model._meta.app_label, obj.model._meta.object_name
),
hint=None,
obj=obj.__class__,
id='admin.E303'
)
@ -79,7 +76,6 @@ class GenericInlineModelAdminChecks(InlineModelAdminChecks):
"'%s.%s' has no GenericForeignKey using content type field '%s' and object ID field '%s'." % (
obj.model._meta.app_label, obj.model._meta.object_name, obj.ct_field, obj.ct_fk_field
),
hint=None,
obj=obj.__class__,
id='admin.E304'
)

View File

@ -92,7 +92,6 @@ class GenericForeignKey(object):
return [
checks.Error(
'Field names must not end with an underscore.',
hint=None,
obj=self,
id='fields.E001',
)
@ -107,7 +106,6 @@ class GenericForeignKey(object):
return [
checks.Error(
"The GenericForeignKey object ID references the non-existent field '%s'." % self.fk_field,
hint=None,
obj=self,
id='contenttypes.E001',
)
@ -128,7 +126,6 @@ class GenericForeignKey(object):
"The GenericForeignKey content type references the non-existent field '%s.%s'." % (
self.model._meta.object_name, self.ct_field
),
hint=None,
obj=self,
id='contenttypes.E002',
)
@ -343,11 +340,10 @@ class GenericRelation(ForeignObject):
else:
return [
checks.Error(
("The GenericRelation defines a relation with the model "
"'%s.%s', but that model does not have a GenericForeignKey.") % (
"The GenericRelation defines a relation with the model "
"'%s.%s', but that model does not have a GenericForeignKey." % (
target._meta.app_label, target._meta.object_name
),
hint=None,
obj=self,
id='contenttypes.E004',
)

View File

@ -48,7 +48,6 @@ class ArrayField(Field):
errors.append(
checks.Error(
'Base field for array cannot be a related field.',
hint=None,
obj=self,
id='postgres.E002'
)
@ -61,7 +60,6 @@ class ArrayField(Field):
errors.append(
checks.Error(
'Base field for array has errors:\n %s' % messages,
hint=None,
obj=self,
id='postgres.E001'
)

View File

@ -29,7 +29,6 @@ class CurrentSiteManager(models.Manager):
return [
checks.Error(
"CurrentSiteManager could not find a field named '%s'." % field_name,
hint=None,
obj=self,
id='sites.E001',
)
@ -41,7 +40,6 @@ class CurrentSiteManager(models.Manager):
"CurrentSiteManager cannot use '%s.%s' as it is not a ForeignKey or ManyToManyField." % (
self.model._meta.object_name, field_name
),
hint=None,
obj=self,
id='sites.E002',
)

View File

@ -20,10 +20,8 @@ def check_all_models(app_configs=None, **kwargs):
if not inspect.ismethod(model.check):
errors.append(
Error(
"The '%s.check()' class method is "
"currently overridden by %r." % (
model.__name__, model.check),
hint=None,
"The '%s.check()' class method is currently overridden by %r."
% (model.__name__, model.check),
obj=model,
id='models.E020'
)
@ -61,7 +59,6 @@ def check_model_signals(app_configs=None, **kwargs):
description, name, '.'.join(reference)
),
obj=receiver.__module__,
hint=None,
id='signals.E001'
)
)

View File

@ -26,8 +26,7 @@ class DatabaseValidation(BaseDatabaseValidation):
and (field.max_length is None or int(field.max_length) > 255)):
errors.append(
checks.Error(
('MySQL does not allow unique CharFields to have a max_length > 255.'),
hint=None,
'MySQL does not allow unique CharFields to have a max_length > 255.',
obj=field,
id='mysql.E001',
)

View File

@ -1194,8 +1194,6 @@ class Model(six.with_metaclass(ModelBase)):
errors.append(
checks.Error(
"'%s' is not of the form 'app_label.app_name'." % cls._meta.swappable,
hint=None,
obj=None,
id='models.E001',
)
)
@ -1207,8 +1205,6 @@ class Model(six.with_metaclass(ModelBase)):
"installed, or is abstract." % (
cls._meta.swappable, app_label, model_name
),
hint=None,
obj=None,
id='models.E002',
)
)
@ -1222,8 +1218,6 @@ class Model(six.with_metaclass(ModelBase)):
errors.append(
checks.Error(
"Proxy model '%s' contains model fields." % cls.__name__,
hint=None,
obj=None,
id='models.E017',
)
)
@ -1272,7 +1266,6 @@ class Model(six.with_metaclass(ModelBase)):
checks.Error(
"The model has two many-to-many relations through "
"the intermediate model '%s'." % f.remote_field.through._meta.label,
hint=None,
obj=cls,
id='models.E003',
)
@ -1293,7 +1286,6 @@ class Model(six.with_metaclass(ModelBase)):
checks.Error(
"'id' can only be used as a field name if the field also "
"sets 'primary_key=True'.",
hint=None,
obj=cls,
id='models.E004',
)
@ -1321,7 +1313,6 @@ class Model(six.with_metaclass(ModelBase)):
clash.name, clash.model._meta,
f.name, f.model._meta
),
hint=None,
obj=cls,
id='models.E005',
)
@ -1352,7 +1343,6 @@ class Model(six.with_metaclass(ModelBase)):
"from model '%s'." % (
f.name, clash.name, clash.model._meta
),
hint=None,
obj=f,
id='models.E006',
)
@ -1394,7 +1384,6 @@ class Model(six.with_metaclass(ModelBase)):
return [
checks.Error(
"'index_together' must be a list or tuple.",
hint=None,
obj=cls,
id='models.E008',
)
@ -1405,7 +1394,6 @@ class Model(six.with_metaclass(ModelBase)):
return [
checks.Error(
"All 'index_together' elements must be lists or tuples.",
hint=None,
obj=cls,
id='models.E009',
)
@ -1424,7 +1412,6 @@ class Model(six.with_metaclass(ModelBase)):
return [
checks.Error(
"'unique_together' must be a list or tuple.",
hint=None,
obj=cls,
id='models.E010',
)
@ -1435,7 +1422,6 @@ class Model(six.with_metaclass(ModelBase)):
return [
checks.Error(
"All 'unique_together' elements must be lists or tuples.",
hint=None,
obj=cls,
id='models.E011',
)
@ -1467,7 +1453,6 @@ class Model(six.with_metaclass(ModelBase)):
"'%s' refers to the non-existent field '%s'." % (
option, field_name,
),
hint=None,
obj=cls,
id='models.E012',
)
@ -1480,7 +1465,6 @@ class Model(six.with_metaclass(ModelBase)):
"ManyToManyFields are not permitted in '%s'." % (
option, field_name, option,
),
hint=None,
obj=cls,
id='models.E013',
)
@ -1488,12 +1472,9 @@ class Model(six.with_metaclass(ModelBase)):
elif field not in cls._meta.local_fields:
errors.append(
checks.Error(
("'%s' refers to field '%s' which is not local "
"to model '%s'.") % (
option, field_name, cls._meta.object_name,
),
hint=("This issue may be caused by multi-table "
"inheritance."),
"'%s' refers to field '%s' which is not local to model '%s'."
% (option, field_name, cls._meta.object_name),
hint="This issue may be caused by multi-table inheritance.",
obj=cls,
id='models.E016',
)
@ -1508,7 +1489,6 @@ class Model(six.with_metaclass(ModelBase)):
return [
checks.Error(
"'ordering' and 'order_with_respect_to' cannot be used together.",
hint=None,
obj=cls,
id='models.E021',
),
@ -1520,9 +1500,7 @@ class Model(six.with_metaclass(ModelBase)):
if not isinstance(cls._meta.ordering, (list, tuple)):
return [
checks.Error(
("'ordering' must be a tuple or list "
"(even if you want to order by only one field)."),
hint=None,
"'ordering' must be a tuple or list (even if you want to order by only one field).",
obj=cls,
id='models.E014',
)
@ -1562,7 +1540,6 @@ class Model(six.with_metaclass(ModelBase)):
errors.append(
checks.Error(
"'ordering' refers to the non-existent field '%s'." % invalid_field,
hint=None,
obj=cls,
id='models.E015',
)
@ -1629,9 +1606,10 @@ class Model(six.with_metaclass(ModelBase)):
'Autogenerated column name too long for M2M field '
'"%s". Maximum length is "%s" for database "%s".'
% (rel_name, allowed_len, db_alias),
hint=("Use 'through' to create a separate model "
"for M2M and then set column_name using "
"'db_column'."),
hint=(
"Use 'through' to create a separate model for "
"M2M and then set column_name using 'db_column'."
),
obj=cls,
id='models.E019',
)

View File

@ -217,7 +217,6 @@ class Field(RegisterLookupMixin):
return [
checks.Error(
'Field names must not end with an underscore.',
hint=None,
obj=self,
id='fields.E001',
)
@ -226,7 +225,6 @@ class Field(RegisterLookupMixin):
return [
checks.Error(
'Field names must not contain "__".',
hint=None,
obj=self,
id='fields.E002',
)
@ -235,7 +233,6 @@ class Field(RegisterLookupMixin):
return [
checks.Error(
"'pk' is a reserved word that cannot be used as a field name.",
hint=None,
obj=self,
id='fields.E003',
)
@ -257,7 +254,6 @@ class Field(RegisterLookupMixin):
return [
checks.Error(
"'choices' must be an iterable (e.g., a list or tuple).",
hint=None,
obj=self,
id='fields.E004',
)
@ -267,9 +263,8 @@ class Field(RegisterLookupMixin):
for choice in self.choices):
return [
checks.Error(
("'choices' must be an iterable containing "
"(actual value, human readable name) tuples."),
hint=None,
"'choices' must be an iterable containing "
"(actual value, human readable name) tuples.",
obj=self,
id='fields.E005',
)
@ -284,7 +279,6 @@ class Field(RegisterLookupMixin):
return [
checks.Error(
"'db_index' must be None, True or False.",
hint=None,
obj=self,
id='fields.E006',
)
@ -939,7 +933,6 @@ class AutoField(Field):
return [
checks.Error(
'AutoFields must set primary_key=True.',
hint=None,
obj=self,
id='fields.E100',
),
@ -1103,7 +1096,6 @@ class CharField(Field):
return [
checks.Error(
"CharFields must define a 'max_length' attribute.",
hint=None,
obj=self,
id='fields.E120',
)
@ -1112,7 +1104,6 @@ class CharField(Field):
return [
checks.Error(
"'max_length' must be a positive integer.",
hint=None,
obj=self,
id='fields.E121',
)
@ -1188,7 +1179,6 @@ class DateTimeCheckMixin(object):
"The options auto_now, auto_now_add, and default "
"are mutually exclusive. Only one of these options "
"may be present.",
hint=None,
obj=self,
id='fields.E160',
)
@ -1535,7 +1525,6 @@ class DecimalField(Field):
return [
checks.Error(
"DecimalFields must define a 'decimal_places' attribute.",
hint=None,
obj=self,
id='fields.E130',
)
@ -1544,7 +1533,6 @@ class DecimalField(Field):
return [
checks.Error(
"'decimal_places' must be a non-negative integer.",
hint=None,
obj=self,
id='fields.E131',
)
@ -1561,7 +1549,6 @@ class DecimalField(Field):
return [
checks.Error(
"DecimalFields must define a 'max_digits' attribute.",
hint=None,
obj=self,
id='fields.E132',
)
@ -1570,7 +1557,6 @@ class DecimalField(Field):
return [
checks.Error(
"'max_digits' must be a positive integer.",
hint=None,
obj=self,
id='fields.E133',
)
@ -1583,7 +1569,6 @@ class DecimalField(Field):
return [
checks.Error(
"'max_digits' must be greater or equal to 'decimal_places'.",
hint=None,
obj=self,
id='fields.E134',
)
@ -1762,7 +1747,6 @@ class FilePathField(Field):
return [
checks.Error(
"FilePathFields must have either 'allow_files' or 'allow_folders' set to True.",
hint=None,
obj=self,
id='fields.E140',
)
@ -1982,9 +1966,8 @@ class GenericIPAddressField(Field):
if not getattr(self, 'null', False) and getattr(self, 'blank', False):
return [
checks.Error(
('GenericIPAddressFields cannot have blank=True if null=False, '
'as blank values are stored as nulls.'),
hint=None,
'GenericIPAddressFields cannot have blank=True if null=False, '
'as blank values are stored as nulls.',
obj=self,
id='fields.E150',
)

View File

@ -245,7 +245,6 @@ class FileField(Field):
return [
checks.Error(
"'unique' is not a valid argument for a %s." % self.__class__.__name__,
hint=None,
obj=self,
id='fields.E200',
)
@ -258,7 +257,6 @@ class FileField(Field):
return [
checks.Error(
"'primary_key' is not a valid argument for a %s." % self.__class__.__name__,
hint=None,
obj=self,
id='fields.E201',
)

View File

@ -153,9 +153,8 @@ class RelatedField(Field):
if rel_is_missing and (rel_is_string or not self.remote_field.model._meta.swapped):
return [
checks.Error(
("Field defines a relation with model '%s', which "
"is either not installed, or is abstract.") % model_name,
hint=None,
"Field defines a relation with model '%s', which is either "
"not installed, or is abstract." % model_name,
obj=self,
id='fields.E300',
)
@ -172,8 +171,8 @@ class RelatedField(Field):
)
return [
checks.Error(
("Field defines a relation with the model '%s', "
"which has been swapped out.") % model,
"Field defines a relation with the model '%s', which has "
"been swapped out." % model,
hint="Update the relation to point at 'settings.%s'." % self.remote_field.model._meta.swappable,
obj=self,
id='fields.E301',
@ -511,9 +510,8 @@ class ForeignObject(RelatedField):
model_name = self.remote_field.model.__name__
return [
checks.Error(
("'%s.%s' must set unique=True "
"because it is referenced by a foreign key.") % (model_name, field_name),
hint=None,
"'%s.%s' must set unique=True because it is referenced by "
"a foreign key." % (model_name, field_name),
obj=self,
id='fields.E311',
)
@ -1161,7 +1159,6 @@ class ManyToManyField(RelatedField):
return [
checks.Error(
'ManyToManyFields cannot be unique.',
hint=None,
obj=self,
id='fields.E330',
)
@ -1175,7 +1172,6 @@ class ManyToManyField(RelatedField):
warnings.append(
checks.Warning(
'null has no effect on ManyToManyField.',
hint=None,
obj=self,
id='fields.W340',
)
@ -1185,7 +1181,6 @@ class ManyToManyField(RelatedField):
warnings.append(
checks.Warning(
'ManyToManyField does not support validators.',
hint=None,
obj=self,
id='fields.W341',
)
@ -1206,23 +1201,19 @@ class ManyToManyField(RelatedField):
# The relationship model is not installed.
errors.append(
checks.Error(
("Field specifies a many-to-many relation through model "
"'%s', which has not been installed.") %
qualified_model_name,
hint=None,
"Field specifies a many-to-many relation through model "
"'%s', which has not been installed." % qualified_model_name,
obj=self,
id='fields.E331',
)
)
else:
assert from_model is not None, (
"ManyToManyField with intermediate "
"tables cannot be checked if you don't pass the model "
"where the field is attached to."
)
# Set some useful local variables
to_model = resolve_relation(from_model, self.remote_field.model)
from_model_name = from_model._meta.object_name
@ -1239,7 +1230,6 @@ class ManyToManyField(RelatedField):
errors.append(
checks.Error(
'Many-to-many fields with intermediate tables must not be symmetrical.',
hint=None,
obj=self,
id='fields.E332',
)
@ -1253,13 +1243,12 @@ class ManyToManyField(RelatedField):
if seen_self > 2 and not self.remote_field.through_fields:
errors.append(
checks.Error(
("The model is used as an intermediate model by "
"'%s', but it has more than two foreign keys "
"to '%s', which is ambiguous. You must specify "
"which two foreign keys Django should use via the "
"through_fields keyword argument.") % (self, from_model_name),
hint=("Use through_fields to specify which two "
"foreign keys Django should use."),
"The model is used as an intermediate model by "
"'%s', but it has more than two foreign keys "
"to '%s', which is ambiguous. You must specify "
"which two foreign keys Django should use via the "
"through_fields keyword argument." % (self, from_model_name),
hint="Use through_fields to specify which two foreign keys Django should use.",
obj=self.remote_field.through,
id='fields.E333',
)
@ -1280,9 +1269,10 @@ class ManyToManyField(RelatedField):
"from '%s', which is ambiguous. You must specify "
"which foreign key Django should use via the "
"through_fields keyword argument.") % (self, from_model_name),
hint=('If you want to create a recursive relationship, '
'use ForeignKey("self", symmetrical=False, '
'through="%s").') % relationship_model_name,
hint=(
'If you want to create a recursive relationship, '
'use ForeignKey("self", symmetrical=False, through="%s").'
) % relationship_model_name,
obj=self,
id='fields.E334',
)
@ -1291,14 +1281,15 @@ class ManyToManyField(RelatedField):
if seen_to > 1 and not self.remote_field.through_fields:
errors.append(
checks.Error(
("The model is used as an intermediate model by "
"'%s', but it has more than one foreign key "
"to '%s', which is ambiguous. You must specify "
"which foreign key Django should use via the "
"through_fields keyword argument.") % (self, to_model_name),
hint=('If you want to create a recursive '
'relationship, use ForeignKey("self", '
'symmetrical=False, through="%s").') % relationship_model_name,
"The model is used as an intermediate model by "
"'%s', but it has more than one foreign key "
"to '%s', which is ambiguous. You must specify "
"which foreign key Django should use via the "
"through_fields keyword argument." % (self, to_model_name),
hint=(
'If you want to create a recursive relationship, '
'use ForeignKey("self", symmetrical=False, through="%s").'
) % relationship_model_name,
obj=self,
id='fields.E335',
)
@ -1307,11 +1298,10 @@ class ManyToManyField(RelatedField):
if seen_from == 0 or seen_to == 0:
errors.append(
checks.Error(
("The model is used as an intermediate model by "
"'%s', but it does not have a foreign key to '%s' or '%s'.") % (
"The model is used as an intermediate model by "
"'%s', but it does not have a foreign key to '%s' or '%s'." % (
self, from_model_name, to_model_name
),
hint=None,
obj=self.remote_field.through,
id='fields.E336',
)
@ -1325,12 +1315,10 @@ class ManyToManyField(RelatedField):
self.remote_field.through_fields[0] and self.remote_field.through_fields[1]):
errors.append(
checks.Error(
("Field specifies 'through_fields' but does not "
"provide the names of the two link fields that should be "
"used for the relation through model "
"'%s'.") % qualified_model_name,
hint=("Make sure you specify 'through_fields' as "
"through_fields=('field1', 'field2')"),
"Field specifies 'through_fields' but does not provide "
"the names of the two link fields that should be used "
"for the relation through model '%s'." % qualified_model_name,
hint="Make sure you specify 'through_fields' as through_fields=('field1', 'field2')",
obj=self,
id='fields.E337',
)
@ -1357,9 +1345,10 @@ class ManyToManyField(RelatedField):
if hasattr(f, 'remote_field') and getattr(f.remote_field, 'model', None) == related_model:
possible_field_names.append(f.name)
if possible_field_names:
hint = ("Did you mean one of the following foreign "
"keys to '%s': %s?") % (related_model._meta.object_name,
', '.join(possible_field_names))
hint = "Did you mean one of the following foreign keys to '%s': %s?" % (
related_model._meta.object_name,
', '.join(possible_field_names),
)
else:
hint = None
@ -1368,8 +1357,8 @@ class ManyToManyField(RelatedField):
except exceptions.FieldDoesNotExist:
errors.append(
checks.Error(
("The intermediary model '%s' has no field '%s'.") % (
qualified_model_name, field_name),
"The intermediary model '%s' has no field '%s'."
% (qualified_model_name, field_name),
hint=hint,
obj=self,
id='fields.E338',
@ -1382,7 +1371,8 @@ class ManyToManyField(RelatedField):
checks.Error(
"'%s.%s' is not a foreign key to '%s'." % (
through._meta.object_name, field_name,
related_model._meta.object_name),
related_model._meta.object_name,
),
hint=hint,
obj=self,
id='fields.E339',

View File

@ -17,7 +17,7 @@ API Reference
``CheckMessage``
-----------------
.. class:: CheckMessage(level, msg, hint, obj=None, id=None)
.. class:: CheckMessage(level, msg, hint=None, obj=None, id=None)
The warnings and errors raised by system checks must be instances of
``CheckMessage``. An instance encapsulates a single reportable error or
@ -60,11 +60,11 @@ There are subclasses to make creating messages with common levels easier. When
using them you can omit the ``level`` argument because it is implied by the
class name.
.. class:: Debug(msg, hint, obj=None, id=None)
.. class:: Info(msg, hint, obj=None, id=None)
.. class:: Warning(msg, hint, obj=None, id=None)
.. class:: Error(msg, hint, obj=None, id=None)
.. class:: Critical(msg, hint, obj=None, id=None)
.. class:: Debug(msg, hint=None, obj=None, id=None)
.. class:: Info(msg, hint=None, obj=None, id=None)
.. class:: Warning(msg, hint=None obj=None, id=None)
.. class:: Error(msg, hint=None, obj=None, id=None)
.. class:: Critical(msg, hint=None, obj=None, id=None)
Builtin checks
==============

View File

@ -39,7 +39,7 @@ check function::
errors.append(
Error(
'an error',
hint=None,
hint='A hint.',
obj=checked_object,
id='myapp.E001',
)
@ -195,7 +195,7 @@ Messages are comparable. That allows you to easily write tests::
expected_errors = [
Error(
'an error',
hint=None,
hint='A hint.',
obj=checked_object,
id='myapp.E001',
)

View File

@ -116,7 +116,6 @@ class SystemChecksTestCase(SimpleTestCase):
checks.Error(
"The value of 'list_editable[0]' refers to 'original_release', "
"which is not contained in 'list_display'.",
hint=None,
obj=SongAdmin,
id='admin.E122',
)
@ -136,9 +135,8 @@ class SystemChecksTestCase(SimpleTestCase):
errors = SongAdmin(Song, AdminSite()).check()
expected = [
checks.Error(
("The value of 'list_editable[0]' refers to 'original_release', "
"which is not editable through the admin."),
hint=None,
"The value of 'list_editable[0]' refers to 'original_release', "
"which is not editable through the admin.",
obj=SongAdmin,
id='admin.E125',
)
@ -191,7 +189,6 @@ class SystemChecksTestCase(SimpleTestCase):
expected = [
checks.Error(
"The value of 'fieldsets[0][1]['fields']' must be a list or tuple.",
hint=None,
obj=NotATupleAdmin,
id='admin.E008',
)
@ -216,7 +213,6 @@ class SystemChecksTestCase(SimpleTestCase):
expected = [
checks.Error(
"The value of 'fieldsets[1][1]['fields']' must be a list or tuple.",
hint=None,
obj=NotATupleAdmin,
id='admin.E008',
)
@ -234,7 +230,6 @@ class SystemChecksTestCase(SimpleTestCase):
expected = [
checks.Error(
"The value of 'exclude' must be a list or tuple.",
hint=None,
obj=ExcludedFields1,
id='admin.E014',
)
@ -249,7 +244,6 @@ class SystemChecksTestCase(SimpleTestCase):
expected = [
checks.Error(
"The value of 'exclude' contains duplicate field(s).",
hint=None,
obj=ExcludedFields2,
id='admin.E015',
)
@ -269,7 +263,6 @@ class SystemChecksTestCase(SimpleTestCase):
expected = [
checks.Error(
"The value of 'exclude' must be a list or tuple.",
hint=None,
obj=ExcludedFieldsInline,
id='admin.E014',
)
@ -292,9 +285,8 @@ class SystemChecksTestCase(SimpleTestCase):
errors = AlbumAdmin(Album, AdminSite()).check()
expected = [
checks.Error(
("Cannot exclude the field 'album', because it is the foreign key "
"to the parent model 'admin_checks.Album'."),
hint=None,
"Cannot exclude the field 'album', because it is the foreign key "
"to the parent model 'admin_checks.Album'.",
obj=SongInline,
id='admin.E201',
)
@ -330,7 +322,6 @@ class SystemChecksTestCase(SimpleTestCase):
expected = [
checks.Error(
"'admin_checks.Book' has no GenericForeignKey.",
hint=None,
obj=BookInline,
id='admin.E301',
)
@ -350,7 +341,6 @@ class SystemChecksTestCase(SimpleTestCase):
expected = [
checks.Error(
"'ct_field' references 'nonexistent', which is not a field on 'admin_checks.Influence'.",
hint=None,
obj=InfluenceInline,
id='admin.E302',
)
@ -370,7 +360,6 @@ class SystemChecksTestCase(SimpleTestCase):
expected = [
checks.Error(
"'ct_fk_field' references 'nonexistent', which is not a field on 'admin_checks.Influence'.",
hint=None,
obj=InfluenceInline,
id='admin.E303',
)
@ -394,7 +383,6 @@ class SystemChecksTestCase(SimpleTestCase):
checks.Error(
"'admin_checks.Influence' has no GenericForeignKey using "
"content type field 'name' and object ID field 'object_id'.",
hint=None,
obj=InfluenceInline,
id='admin.E304',
)
@ -418,7 +406,6 @@ class SystemChecksTestCase(SimpleTestCase):
checks.Error(
"'admin_checks.Influence' has no GenericForeignKey using "
"content type field 'content_type' and object ID field 'name'.",
hint=None,
obj=InfluenceInline,
id='admin.E304',
)
@ -437,7 +424,6 @@ class SystemChecksTestCase(SimpleTestCase):
checks.Error(
"The value of 'raw_id_fields[0]' refers to 'nonexisting', "
"which is not an attribute of 'admin_checks.Album'.",
hint=None,
obj=RawIdNonexistingAdmin,
id='admin.E002',
)
@ -472,7 +458,6 @@ class SystemChecksTestCase(SimpleTestCase):
expected = [
checks.Error(
"'admin_checks.TwoAlbumFKAndAnE' has more than one ForeignKey to 'admin_checks.Album'.",
hint=None,
obj=TwoAlbumFKAndAnEInline,
id='admin.E202',
)
@ -545,9 +530,8 @@ class SystemChecksTestCase(SimpleTestCase):
errors = SongAdmin(Song, AdminSite()).check()
expected = [
checks.Error(
("The value of 'readonly_fields[1]' is not a callable, an attribute "
"of 'SongAdmin', or an attribute of 'admin_checks.Song'."),
hint=None,
"The value of 'readonly_fields[1]' is not a callable, an attribute "
"of 'SongAdmin', or an attribute of 'admin_checks.Song'.",
obj=SongAdmin,
id='admin.E035',
)
@ -562,9 +546,8 @@ class SystemChecksTestCase(SimpleTestCase):
errors = CityInline(State, AdminSite()).check()
expected = [
checks.Error(
("The value of 'readonly_fields[0]' is not a callable, an attribute "
"of 'CityInline', or an attribute of 'admin_checks.City'."),
hint=None,
"The value of 'readonly_fields[0]' is not a callable, an attribute "
"of 'CityInline', or an attribute of 'admin_checks.City'.",
obj=CityInline,
id='admin.E035',
)
@ -600,9 +583,8 @@ class SystemChecksTestCase(SimpleTestCase):
errors = BookAdmin(Book, AdminSite()).check()
expected = [
checks.Error(
("The value of 'fields' cannot include the ManyToManyField 'authors', "
"because that field manually specifies a relationship model."),
hint=None,
"The value of 'fields' cannot include the ManyToManyField 'authors', "
"because that field manually specifies a relationship model.",
obj=BookAdmin,
id='admin.E013',
)
@ -619,9 +601,8 @@ class SystemChecksTestCase(SimpleTestCase):
errors = FieldsetBookAdmin(Book, AdminSite()).check()
expected = [
checks.Error(
("The value of 'fieldsets[1][1][\"fields\"]' cannot include the ManyToManyField "
"'authors', because that field manually specifies a relationship model."),
hint=None,
"The value of 'fieldsets[1][1][\"fields\"]' cannot include the ManyToManyField "
"'authors', because that field manually specifies a relationship model.",
obj=FieldsetBookAdmin,
id='admin.E013',
)
@ -701,7 +682,6 @@ class SystemChecksTestCase(SimpleTestCase):
expected = [
checks.Error(
"The value of 'fields' contains duplicate field(s).",
hint=None,
obj=MyModelAdmin,
id='admin.E006'
)
@ -720,7 +700,6 @@ class SystemChecksTestCase(SimpleTestCase):
expected = [
checks.Error(
"There are duplicate field(s) in 'fieldsets[0][1]'.",
hint=None,
obj=MyModelAdmin,
id='admin.E012'
)

View File

@ -9,19 +9,7 @@ class ModelRaisingMessages(models.Model):
@classmethod
def check(self, **kwargs):
return [
checks.Warning(
'First warning',
hint='Hint',
obj='obj'
),
checks.Warning(
'Second warning',
hint=None,
obj='a'
),
checks.Error(
'An error',
hint='Error hint',
obj=None,
)
checks.Warning('First warning', hint='Hint', obj='obj'),
checks.Warning('Second warning', obj='a'),
checks.Error('An error', hint='Error hint'),
]

View File

@ -8,9 +8,4 @@ from django.db import models
class ModelRaisingMessages(models.Model):
@classmethod
def check(self, **kwargs):
return [
checks.Warning(
'A warning',
hint=None,
),
]
return [checks.Warning('A warning')]

View File

@ -5845,7 +5845,6 @@ class AdminViewOnSiteTests(TestCase):
self.assertEqual(admin.check(), [
Error(
"The value of 'view_on_site' must be a callable or a boolean value.",
hint=None,
obj=CityAdmin,
id='admin.E025',
),

View File

@ -584,7 +584,6 @@ class CustomUserModelValidationTestCase(SimpleTestCase):
expected = [
checks.Error(
"'REQUIRED_FIELDS' must be a list or tuple.",
hint=None,
obj=CustomUserNonListRequiredFields,
id='auth.E001',
),
@ -606,9 +605,8 @@ class CustomUserModelValidationTestCase(SimpleTestCase):
errors = checks.run_checks(apps.get_app_configs())
expected = [
checks.Error(
("The field named as the 'USERNAME_FIELD' for a custom user model "
"must not be included in 'REQUIRED_FIELDS'."),
hint=None,
"The field named as the 'USERNAME_FIELD' for a custom user model "
"must not be included in 'REQUIRED_FIELDS'.",
obj=CustomUserBadRequiredFields,
id='auth.E002',
),
@ -625,9 +623,8 @@ class CustomUserModelValidationTestCase(SimpleTestCase):
errors = checks.run_checks()
expected = [
checks.Error(
("'CustomUserNonUniqueUsername.username' must be "
"unique because it is named as the 'USERNAME_FIELD'."),
hint=None,
"'CustomUserNonUniqueUsername.username' must be "
"unique because it is named as the 'USERNAME_FIELD'.",
obj=CustomUserNonUniqueUsername,
id='auth.E003',
),
@ -637,10 +634,9 @@ class CustomUserModelValidationTestCase(SimpleTestCase):
errors = checks.run_checks()
expected = [
checks.Warning(
("'CustomUserNonUniqueUsername.username' is named as "
"the 'USERNAME_FIELD', but it is not unique."),
hint=('Ensure that your authentication backend(s) can handle '
'non-unique usernames.'),
"'CustomUserNonUniqueUsername.username' is named as "
"the 'USERNAME_FIELD', but it is not unique.",
hint='Ensure that your authentication backend(s) can handle non-unique usernames.',
obj=CustomUserNonUniqueUsername,
id='auth.W004',
)

View File

@ -17,7 +17,6 @@ class TestDeprecatedField(SimpleTestCase):
self.assertEqual(model.check(), [
checks.Warning(
msg='MyField has been deprecated.',
hint=None,
obj=Model._meta.get_field('name'),
id='fields.WXXX',
)
@ -58,7 +57,6 @@ class TestRemovedField(SimpleTestCase):
self.assertEqual(model.check(), [
checks.Error(
msg='MyField has been removed except for support in historical migrations.',
hint=None,
obj=Model._meta.get_field('name'),
id='fields.EXXX',
)

View File

@ -79,12 +79,12 @@ class MessageTests(SimpleTestCase):
self.assertEqual(force_text(e), expected)
def test_printing_no_hint(self):
e = Error("Message", hint=None, obj=DummyObj())
e = Error("Message", obj=DummyObj())
expected = "obj: Message"
self.assertEqual(force_text(e), expected)
def test_printing_no_object(self):
e = Error("Message", hint="Hint", obj=None)
e = Error("Message", hint="Hint")
expected = "?: Message\n\tHINT: Hint"
self.assertEqual(force_text(e), expected)
@ -95,18 +95,18 @@ class MessageTests(SimpleTestCase):
def test_printing_field_error(self):
field = SimpleModel._meta.get_field('field')
e = Error("Error", hint=None, obj=field)
e = Error("Error", obj=field)
expected = "check_framework.SimpleModel.field: Error"
self.assertEqual(force_text(e), expected)
def test_printing_model_error(self):
e = Error("Error", hint=None, obj=SimpleModel)
e = Error("Error", obj=SimpleModel)
expected = "check_framework.SimpleModel: Error"
self.assertEqual(force_text(e), expected)
def test_printing_manager_error(self):
manager = SimpleModel.manager
e = Error("Error", hint=None, obj=manager)
e = Error("Error", obj=manager)
expected = "check_framework.SimpleModel.manager: Error"
self.assertEqual(force_text(e), expected)
@ -202,23 +202,11 @@ class CheckCommandTests(SimpleTestCase):
def custom_error_system_check(app_configs, **kwargs):
return [
Error(
'Error',
hint=None,
id='myerrorcheck.E001',
)
]
return [Error('Error', id='myerrorcheck.E001')]
def custom_warning_system_check(app_configs, **kwargs):
return [
Warning(
'Warning',
hint=None,
id='mywarningcheck.E001',
)
]
return [Warning('Warning', id='mywarningcheck.E001')]
class SilencingCheckTests(SimpleTestCase):
@ -283,21 +271,18 @@ class CheckFrameworkReservedNamesTests(SimpleTestCase):
Error(
"The 'ModelWithAttributeCalledCheck.check()' class method is "
"currently overridden by 42.",
hint=None,
obj=ModelWithAttributeCalledCheck,
id='models.E020'
),
Error(
"The 'ModelWithRelatedManagerCalledCheck.check()' class method is "
"currently overridden by %r." % ModelWithRelatedManagerCalledCheck.check,
hint=None,
obj=ModelWithRelatedManagerCalledCheck,
id='models.E020'
),
Error(
"The 'ModelWithDescriptorCalledCheck.check()' class method is "
"currently overridden by %r." % ModelWithDescriptorCalledCheck.check,
hint=None,
obj=ModelWithDescriptorCalledCheck,
id='models.E020'
),

View File

@ -135,7 +135,6 @@ class GenericForeignKeyTests(SimpleTestCase):
expected = [
checks.Error(
"The GenericForeignKey content type references the non-existent field 'TaggedItem.content_type'.",
hint=None,
obj=TaggedItem.content_object,
id='contenttypes.E002',
)
@ -194,7 +193,6 @@ class GenericForeignKeyTests(SimpleTestCase):
expected = [
checks.Error(
"The GenericForeignKey object ID references the non-existent field 'object_id'.",
hint=None,
obj=TaggedItem.content_object,
id='contenttypes.E001',
)
@ -212,7 +210,6 @@ class GenericForeignKeyTests(SimpleTestCase):
expected = [
checks.Error(
'Field names must not end with an underscore.',
hint=None,
obj=Model.content_object_,
id='fields.E001',
)
@ -269,9 +266,8 @@ class GenericRelationshipTests(SimpleTestCase):
errors = Model.rel.field.check()
expected = [
checks.Error(
("Field defines a relation with model 'MissingModel', "
"which is either not installed, or is abstract."),
hint=None,
"Field defines a relation with model 'MissingModel', "
"which is either not installed, or is abstract.",
obj=Model.rel.field,
id='fields.E300',
)
@ -300,10 +296,9 @@ class GenericRelationshipTests(SimpleTestCase):
errors = Bookmark.tags.field.check()
expected = [
checks.Error(
("The GenericRelation defines a relation with the model "
"'contenttypes_tests.TaggedItem', but that model does not have a "
"GenericForeignKey."),
hint=None,
"The GenericRelation defines a relation with the model "
"'contenttypes_tests.TaggedItem', but that model does not have a "
"GenericForeignKey.",
obj=Bookmark.tags.field,
id='contenttypes.E004',
)
@ -329,9 +324,9 @@ class GenericRelationshipTests(SimpleTestCase):
errors = Model.rel.field.check()
expected = [
checks.Error(
("Field defines a relation with the model "
"'contenttypes_tests.SwappedModel', "
"which has been swapped out."),
"Field defines a relation with the model "
"'contenttypes_tests.SwappedModel', "
"which has been swapped out.",
hint="Update the relation to point at 'settings.TEST_SWAPPED_MODEL'.",
obj=Model.rel.field,
id='fields.E301',
@ -352,7 +347,6 @@ class GenericRelationshipTests(SimpleTestCase):
expected = [
checks.Error(
'Field names must not end with an underscore.',
hint=None,
obj=InvalidBookmark.tags_.field,
id='fields.E001',
)

View File

@ -19,7 +19,7 @@ class BackendSpecificChecksTests(SimpleTestCase):
@mock.patch('django.db.models.fields.router.allow_migrate', new=dummy_allow_migrate)
def test_check_field(self):
""" Test if backend specific checks are performed. """
error = Error('an error', hint=None)
error = Error('an error')
class Model(models.Model):
field = models.IntegerField()

View File

@ -42,7 +42,6 @@ class IndexTogetherTests(SimpleTestCase):
expected = [
Error(
"'index_together' must be a list or tuple.",
hint=None,
obj=Model,
id='models.E008',
),
@ -58,7 +57,6 @@ class IndexTogetherTests(SimpleTestCase):
expected = [
Error(
"'index_together' must be a list or tuple.",
hint=None,
obj=Model,
id='models.E008',
),
@ -74,7 +72,6 @@ class IndexTogetherTests(SimpleTestCase):
expected = [
Error(
"All 'index_together' elements must be lists or tuples.",
hint=None,
obj=Model,
id='models.E009',
),
@ -92,7 +89,6 @@ class IndexTogetherTests(SimpleTestCase):
expected = [
Error(
"'index_together' refers to the non-existent field 'missing_field'.",
hint=None,
obj=Model,
id='models.E012',
),
@ -137,7 +133,6 @@ class IndexTogetherTests(SimpleTestCase):
Error(
"'index_together' refers to a ManyToManyField 'm2m', but "
"ManyToManyFields are not permitted in 'index_together'.",
hint=None,
obj=Model,
id='models.E013',
),
@ -158,7 +153,6 @@ class UniqueTogetherTests(SimpleTestCase):
expected = [
Error(
"'unique_together' must be a list or tuple.",
hint=None,
obj=Model,
id='models.E010',
),
@ -177,7 +171,6 @@ class UniqueTogetherTests(SimpleTestCase):
expected = [
Error(
"All 'unique_together' elements must be lists or tuples.",
hint=None,
obj=Model,
id='models.E011',
),
@ -193,7 +186,6 @@ class UniqueTogetherTests(SimpleTestCase):
expected = [
Error(
"'unique_together' must be a list or tuple.",
hint=None,
obj=Model,
id='models.E010',
),
@ -223,7 +215,6 @@ class UniqueTogetherTests(SimpleTestCase):
expected = [
Error(
"'unique_together' refers to the non-existent field 'missing_field'.",
hint=None,
obj=Model,
id='models.E012',
),
@ -244,7 +235,6 @@ class UniqueTogetherTests(SimpleTestCase):
Error(
"'unique_together' refers to a ManyToManyField 'm2m', but "
"ManyToManyFields are not permitted in 'unique_together'.",
hint=None,
obj=Model,
id='models.E013',
),
@ -264,13 +254,11 @@ class FieldNamesTests(SimpleTestCase):
expected = [
Error(
'Field names must not end with an underscore.',
hint=None,
obj=Model._meta.get_field('field_'),
id='fields.E001',
),
Error(
'Field names must not end with an underscore.',
hint=None,
obj=Model._meta.get_field('m2m_'),
id='fields.E001',
),
@ -413,7 +401,6 @@ class FieldNamesTests(SimpleTestCase):
expected = [
Error(
'Field names must not contain "__".',
hint=None,
obj=Model._meta.get_field('some__field'),
id='fields.E002',
)
@ -428,7 +415,6 @@ class FieldNamesTests(SimpleTestCase):
expected = [
Error(
"'pk' is a reserved word that cannot be used as a field name.",
hint=None,
obj=Model._meta.get_field('pk'),
id='fields.E003',
)
@ -451,7 +437,6 @@ class ShadowingFieldsTests(SimpleTestCase):
Error(
"The field 'child' clashes with the field "
"'child' from model 'invalid_models_tests.parent'.",
hint=None,
obj=Child._meta.get_field('child'),
id='models.E006',
)
@ -476,7 +461,6 @@ class ShadowingFieldsTests(SimpleTestCase):
"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',
),
@ -484,7 +468,6 @@ class ShadowingFieldsTests(SimpleTestCase):
"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',
)
@ -508,7 +491,6 @@ class ShadowingFieldsTests(SimpleTestCase):
Error(
"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',
)
@ -533,7 +515,6 @@ class ShadowingFieldsTests(SimpleTestCase):
Error(
"The field 'clash' clashes with the field 'clash' "
"from model 'invalid_models_tests.grandparent'.",
hint=None,
obj=GrandChild._meta.get_field('clash'),
id='models.E006',
)
@ -553,7 +534,6 @@ class ShadowingFieldsTests(SimpleTestCase):
Error(
"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',
)
@ -575,7 +555,6 @@ class OtherModelTests(SimpleTestCase):
Error(
"'id' can only be used as a field name if the field also sets "
"'primary_key=True'.",
hint=None,
obj=Model,
id='models.E004',
),
@ -592,7 +571,6 @@ class OtherModelTests(SimpleTestCase):
Error(
"'ordering' must be a tuple or list "
"(even if you want to order by only one field).",
hint=None,
obj=Model,
id='models.E014',
),
@ -636,7 +614,6 @@ class OtherModelTests(SimpleTestCase):
expected = [
Error(
"'ordering' and 'order_with_respect_to' cannot be used together.",
hint=None,
obj=Answer,
id='models.E021',
),
@ -657,7 +634,6 @@ class OtherModelTests(SimpleTestCase):
expected = [
Error(
"'ordering' refers to the non-existent field 'relation'.",
hint=None,
obj=Model,
id='models.E015',
),
@ -673,7 +649,6 @@ class OtherModelTests(SimpleTestCase):
expected = [
Error(
"'ordering' refers to the non-existent field 'missing_field'.",
hint=None,
obj=Model,
id='models.E015',
)
@ -693,7 +668,6 @@ class OtherModelTests(SimpleTestCase):
expected = [
Error(
"'ordering' refers to the non-existent field 'missing_fk_field_id'.",
hint=None,
obj=Model,
id='models.E015',
)
@ -724,8 +698,6 @@ class OtherModelTests(SimpleTestCase):
expected = [
Error(
"'TEST_SWAPPED_MODEL_BAD_VALUE' is not of the form 'app_label.app_name'.",
hint=None,
obj=None,
id='models.E001',
),
]
@ -742,8 +714,6 @@ class OtherModelTests(SimpleTestCase):
Error(
"'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',
),
]
@ -768,7 +738,6 @@ class OtherModelTests(SimpleTestCase):
Error(
"The model has two many-to-many relations through "
"the intermediate model 'invalid_models_tests.Membership'.",
hint=None,
obj=Group,
id='models.E003',
)

View File

@ -37,7 +37,6 @@ class AutoFieldTests(SimpleTestCase):
expected = [
Error(
'AutoFields must set primary_key=True.',
hint=None,
obj=field,
id='fields.E100',
),
@ -92,7 +91,6 @@ class CharFieldTests(TestCase):
expected = [
Error(
"CharFields must define a 'max_length' attribute.",
hint=None,
obj=field,
id='fields.E120',
),
@ -108,7 +106,6 @@ class CharFieldTests(TestCase):
expected = [
Error(
"'max_length' must be a positive integer.",
hint=None,
obj=field,
id='fields.E121',
),
@ -124,7 +121,6 @@ class CharFieldTests(TestCase):
expected = [
Error(
"'max_length' must be a positive integer.",
hint=None,
obj=field,
id='fields.E121',
),
@ -140,7 +136,6 @@ class CharFieldTests(TestCase):
expected = [
Error(
"'max_length' must be a positive integer.",
hint=None,
obj=field,
id='fields.E121',
),
@ -156,7 +151,6 @@ class CharFieldTests(TestCase):
expected = [
Error(
"'choices' must be an iterable (e.g., a list or tuple).",
hint=None,
obj=field,
id='fields.E004',
),
@ -172,7 +166,6 @@ class CharFieldTests(TestCase):
expected = [
Error(
"'choices' must be an iterable containing (actual value, human readable name) tuples.",
hint=None,
obj=field,
id='fields.E005',
),
@ -188,7 +181,6 @@ class CharFieldTests(TestCase):
expected = [
Error(
"'db_index' must be None, True or False.",
hint=None,
obj=field,
id='fields.E006',
),
@ -209,7 +201,6 @@ class CharFieldTests(TestCase):
expected = [
Error(
'MySQL does not allow unique CharFields to have a max_length > 255.',
hint=None,
obj=field,
id='mysql.E001',
)
@ -235,7 +226,6 @@ class DateFieldTests(TestCase):
"The options auto_now, auto_now_add, and default "
"are mutually exclusive. Only one of these options "
"may be present.",
hint=None,
obj=field,
id='fields.E160',
))
@ -341,13 +331,11 @@ class DecimalFieldTests(SimpleTestCase):
expected = [
Error(
"DecimalFields must define a 'decimal_places' attribute.",
hint=None,
obj=field,
id='fields.E130',
),
Error(
"DecimalFields must define a 'max_digits' attribute.",
hint=None,
obj=field,
id='fields.E132',
),
@ -363,13 +351,11 @@ class DecimalFieldTests(SimpleTestCase):
expected = [
Error(
"'decimal_places' must be a non-negative integer.",
hint=None,
obj=field,
id='fields.E131',
),
Error(
"'max_digits' must be a positive integer.",
hint=None,
obj=field,
id='fields.E133',
),
@ -385,13 +371,11 @@ class DecimalFieldTests(SimpleTestCase):
expected = [
Error(
"'decimal_places' must be a non-negative integer.",
hint=None,
obj=field,
id='fields.E131',
),
Error(
"'max_digits' must be a positive integer.",
hint=None,
obj=field,
id='fields.E133',
),
@ -407,7 +391,6 @@ class DecimalFieldTests(SimpleTestCase):
expected = [
Error(
"'max_digits' must be greater or equal to 'decimal_places'.",
hint=None,
obj=field,
id='fields.E134',
),
@ -445,7 +428,6 @@ class FileFieldTests(SimpleTestCase):
expected = [
Error(
"'unique' is not a valid argument for a FileField.",
hint=None,
obj=field,
id='fields.E200',
)
@ -461,7 +443,6 @@ class FileFieldTests(SimpleTestCase):
expected = [
Error(
"'primary_key' is not a valid argument for a FileField.",
hint=None,
obj=field,
id='fields.E201',
)
@ -481,7 +462,6 @@ class FilePathFieldTests(SimpleTestCase):
expected = [
Error(
"FilePathFields must have either 'allow_files' or 'allow_folders' set to True.",
hint=None,
obj=field,
id='fields.E140',
),
@ -502,7 +482,6 @@ class GenericIPAddressFieldTests(SimpleTestCase):
Error(
('GenericIPAddressFields cannot have blank=True if null=False, '
'as blank values are stored as nulls.'),
hint=None,
obj=field,
id='fields.E150',
),

View File

@ -122,9 +122,8 @@ class RelativeFieldTests(SimpleTestCase):
errors = field.check()
expected = [
Error(
("Field defines a relation with model 'Rel1', "
"which is either not installed, or is abstract."),
hint=None,
"Field defines a relation with model 'Rel1', "
"which is either not installed, or is abstract.",
obj=field,
id='fields.E300',
),
@ -154,9 +153,8 @@ class RelativeFieldTests(SimpleTestCase):
errors = field.check(from_model=Model)
expected = [
Error(
("Field defines a relation with model 'Rel2', "
"which is either not installed, or is abstract."),
hint=None,
"Field defines a relation with model 'Rel2', "
"which is either not installed, or is abstract.",
obj=field,
id='fields.E300',
),
@ -191,7 +189,6 @@ class RelativeFieldTests(SimpleTestCase):
expected = [
DjangoWarning(
'null has no effect on ManyToManyField.',
hint=None,
obj=field,
id='fields.W340',
)
@ -199,7 +196,6 @@ class RelativeFieldTests(SimpleTestCase):
expected.append(
DjangoWarning(
'ManyToManyField does not support validators.',
hint=None,
obj=field,
id='fields.W341',
)
@ -213,8 +209,7 @@ class RelativeFieldTests(SimpleTestCase):
pass
class Group(models.Model):
field = models.ManyToManyField('Person',
through="AmbiguousRelationship", related_name='tertiary')
field = models.ManyToManyField('Person', through="AmbiguousRelationship", related_name='tertiary')
class AmbiguousRelationship(models.Model):
# Too much foreign keys to Person.
@ -226,14 +221,15 @@ class RelativeFieldTests(SimpleTestCase):
errors = field.check(from_model=Group)
expected = [
Error(
("The model is used as an intermediate model by "
"'invalid_models_tests.Group.field', but it has more than one "
"foreign key to 'Person', which is ambiguous. You must specify "
"which foreign key Django should use via the through_fields "
"keyword argument."),
hint=('If you want to create a recursive relationship, use '
'ForeignKey("self", symmetrical=False, '
'through="AmbiguousRelationship").'),
"The model is used as an intermediate model by "
"'invalid_models_tests.Group.field', but it has more than one "
"foreign key to 'Person', which is ambiguous. You must specify "
"which foreign key Django should use via the through_fields "
"keyword argument.",
hint=(
'If you want to create a recursive relationship, use '
'ForeignKey("self", symmetrical=False, through="AmbiguousRelationship").'
),
obj=field,
id='fields.E335',
),
@ -248,8 +244,7 @@ class RelativeFieldTests(SimpleTestCase):
pass
class Group(models.Model):
members = models.ManyToManyField('Person',
through="InvalidRelationship")
members = models.ManyToManyField('Person', through="InvalidRelationship")
class InvalidRelationship(models.Model):
person = models.ForeignKey(Person, models.CASCADE)
@ -260,10 +255,9 @@ class RelativeFieldTests(SimpleTestCase):
errors = field.check(from_model=Group)
expected = [
Error(
("The model is used as an intermediate model by "
"'invalid_models_tests.Group.members', but it does not "
"have a foreign key to 'Group' or 'Person'."),
hint=None,
"The model is used as an intermediate model by "
"'invalid_models_tests.Group.members', but it does not "
"have a foreign key to 'Group' or 'Person'.",
obj=InvalidRelationship,
id='fields.E336',
),
@ -275,8 +269,7 @@ class RelativeFieldTests(SimpleTestCase):
pass
class Group(models.Model):
members = models.ManyToManyField('Person',
through="InvalidRelationship")
members = models.ManyToManyField('Person', through="InvalidRelationship")
class InvalidRelationship(models.Model):
group = models.ForeignKey(Group, models.CASCADE)
@ -286,10 +279,9 @@ class RelativeFieldTests(SimpleTestCase):
errors = field.check(from_model=Group)
expected = [
Error(
("The model is used as an intermediate model by "
"'invalid_models_tests.Group.members', but it does not have "
"a foreign key to 'Group' or 'Person'."),
hint=None,
"The model is used as an intermediate model by "
"'invalid_models_tests.Group.members', but it does not have "
"a foreign key to 'Group' or 'Person'.",
obj=InvalidRelationship,
id='fields.E336',
),
@ -301,16 +293,14 @@ class RelativeFieldTests(SimpleTestCase):
pass
class Group(models.Model):
members = models.ManyToManyField('Person',
through="MissingM2MModel")
members = models.ManyToManyField('Person', through="MissingM2MModel")
field = Group._meta.get_field('members')
errors = field.check(from_model=Group)
expected = [
Error(
("Field specifies a many-to-many relation through model "
"'MissingM2MModel', which has not been installed."),
hint=None,
"Field specifies a many-to-many relation through model "
"'MissingM2MModel', which has not been installed.",
obj=field,
id='fields.E331',
),
@ -350,7 +340,6 @@ class RelativeFieldTests(SimpleTestCase):
expected = [
Error(
'Many-to-many fields with intermediate tables must not be symmetrical.',
hint=None,
obj=field,
id='fields.E332',
),
@ -359,8 +348,7 @@ class RelativeFieldTests(SimpleTestCase):
def test_too_many_foreign_keys_in_self_referential_model(self):
class Person(models.Model):
friends = models.ManyToManyField('self',
through="InvalidRelationship", symmetrical=False)
friends = models.ManyToManyField('self', through="InvalidRelationship", symmetrical=False)
class InvalidRelationship(models.Model):
first = models.ForeignKey(Person, models.CASCADE, related_name="rel_from_set_2")
@ -371,11 +359,11 @@ class RelativeFieldTests(SimpleTestCase):
errors = field.check(from_model=Person)
expected = [
Error(
("The model is used as an intermediate model by "
"'invalid_models_tests.Person.friends', but it has more than two "
"foreign keys to 'Person', which is ambiguous. You must specify "
"which two foreign keys Django should use via the through_fields "
"keyword argument."),
"The model is used as an intermediate model by "
"'invalid_models_tests.Person.friends', but it has more than two "
"foreign keys to 'Person', which is ambiguous. You must specify "
"which two foreign keys Django should use via the through_fields "
"keyword argument.",
hint='Use through_fields to specify which two foreign keys Django should use.',
obj=InvalidRelationship,
id='fields.E333',
@ -386,8 +374,7 @@ class RelativeFieldTests(SimpleTestCase):
def test_symmetric_self_reference_with_intermediate_table(self):
class Person(models.Model):
# Explicit symmetrical=True.
friends = models.ManyToManyField('self',
through="Relationship", symmetrical=True)
friends = models.ManyToManyField('self', through="Relationship", symmetrical=True)
class Relationship(models.Model):
first = models.ForeignKey(Person, models.CASCADE, related_name="rel_from_set")
@ -398,7 +385,6 @@ class RelativeFieldTests(SimpleTestCase):
expected = [
Error(
'Many-to-many fields with intermediate tables must not be symmetrical.',
hint=None,
obj=field,
id='fields.E332',
),
@ -412,10 +398,12 @@ class RelativeFieldTests(SimpleTestCase):
"""
class Person(models.Model):
# Explicit symmetrical=True.
friends = models.ManyToManyField('self',
friends = models.ManyToManyField(
'self',
symmetrical=True,
through="Relationship",
through_fields=('first', 'second'))
through_fields=('first', 'second'),
)
class Relationship(models.Model):
first = models.ForeignKey(Person, models.CASCADE, related_name="rel_from_set")
@ -427,7 +415,6 @@ class RelativeFieldTests(SimpleTestCase):
expected = [
Error(
'Many-to-many fields with intermediate tables must not be symmetrical.',
hint=None,
obj=field,
id='fields.E332',
),
@ -492,7 +479,6 @@ class RelativeFieldTests(SimpleTestCase):
expected = [
Error(
'ManyToManyFields cannot be unique.',
hint=None,
obj=field,
id='fields.E330',
),
@ -511,7 +497,6 @@ class RelativeFieldTests(SimpleTestCase):
expected = [
Error(
"'Target.bad' must set unique=True because it is referenced by a foreign key.",
hint=None,
obj=field,
id='fields.E311',
),
@ -530,7 +515,6 @@ class RelativeFieldTests(SimpleTestCase):
expected = [
Error(
"'Target.bad' must set unique=True because it is referenced by a foreign key.",
hint=None,
obj=field,
id='fields.E311',
),
@ -547,10 +531,12 @@ class RelativeFieldTests(SimpleTestCase):
person_country_id = models.IntegerField()
person_city_id = models.IntegerField()
person = models.ForeignObject(Person,
person = models.ForeignObject(
Person,
on_delete=models.CASCADE,
from_fields=['person_country_id', 'person_city_id'],
to_fields=['country_id', 'city_id'])
to_fields=['country_id', 'city_id'],
)
field = MMembership._meta.get_field('person')
errors = field.check()
@ -630,17 +616,21 @@ class RelativeFieldTests(SimpleTestCase):
swappable = 'TEST_SWAPPABLE_MODEL'
class Model(models.Model):
explicit_fk = models.ForeignKey(SwappableModel,
explicit_fk = models.ForeignKey(
SwappableModel,
models.CASCADE,
related_name='explicit_fk')
implicit_fk = models.ForeignKey('invalid_models_tests.SwappableModel',
related_name='explicit_fk',
)
implicit_fk = models.ForeignKey(
'invalid_models_tests.SwappableModel',
models.CASCADE,
related_name='implicit_fk')
explicit_m2m = models.ManyToManyField(SwappableModel,
related_name='explicit_m2m')
related_name='implicit_fk',
)
explicit_m2m = models.ManyToManyField(SwappableModel, related_name='explicit_m2m')
implicit_m2m = models.ManyToManyField(
'invalid_models_tests.SwappableModel',
related_name='implicit_m2m')
related_name='implicit_m2m',
)
explicit_fk = Model._meta.get_field('explicit_fk')
self.assertEqual(explicit_fk.check(), [])
@ -664,17 +654,21 @@ class RelativeFieldTests(SimpleTestCase):
swappable = 'TEST_SWAPPED_MODEL'
class Model(models.Model):
explicit_fk = models.ForeignKey(SwappedModel,
explicit_fk = models.ForeignKey(
SwappedModel,
models.CASCADE,
related_name='explicit_fk')
implicit_fk = models.ForeignKey('invalid_models_tests.SwappedModel',
related_name='explicit_fk',
)
implicit_fk = models.ForeignKey(
'invalid_models_tests.SwappedModel',
models.CASCADE,
related_name='implicit_fk')
explicit_m2m = models.ManyToManyField(SwappedModel,
related_name='explicit_m2m')
related_name='implicit_fk',
)
explicit_m2m = models.ManyToManyField(SwappedModel, related_name='explicit_m2m')
implicit_m2m = models.ManyToManyField(
'invalid_models_tests.SwappedModel',
related_name='implicit_m2m')
related_name='implicit_m2m',
)
fields = [
Model._meta.get_field('explicit_fk'),
@ -838,15 +832,19 @@ class AccessorClashTests(SimpleTestCase):
expected = [
Error(
"Reverse accessor for 'Model.foreign' clashes with reverse accessor for 'Model.m2m'.",
hint=("Add or change a related_name argument to the definition "
"for 'Model.foreign' or 'Model.m2m'."),
hint=(
"Add or change a related_name argument to the definition "
"for 'Model.foreign' or 'Model.m2m'."
),
obj=Model._meta.get_field('foreign'),
id='fields.E304',
),
Error(
"Reverse accessor for 'Model.m2m' clashes with reverse accessor for 'Model.foreign'.",
hint=("Add or change a related_name argument to the definition "
"for 'Model.m2m' or 'Model.foreign'."),
hint=(
"Add or change a related_name argument to the definition "
"for 'Model.m2m' or 'Model.foreign'."
),
obj=Model._meta.get_field('m2m'),
id='fields.E304',
),
@ -873,9 +871,10 @@ class AccessorClashTests(SimpleTestCase):
expected = [
Error(
"Reverse accessor for 'Model.children' clashes with field name 'Child.m2m_clash'.",
hint=("Rename field 'Child.m2m_clash', or add/change "
"a related_name argument to the definition "
"for field 'Model.children'."),
hint=(
"Rename field 'Child.m2m_clash', or add/change a related_name "
"argument to the definition for field 'Model.children'."
),
obj=Model._meta.get_field('children'),
id='fields.E302',
)
@ -930,9 +929,10 @@ class ReverseQueryNameClashTests(SimpleTestCase):
expected = [
Error(
"Reverse query name for 'Model.rel' clashes with field name 'Target.model'.",
hint=("Rename field 'Target.model', or add/change "
"a related_name argument to the definition "
"for field 'Model.rel'."),
hint=(
"Rename field 'Target.model', or add/change a related_name "
"argument to the definition for field 'Model.rel'."
),
obj=Model._meta.get_field('rel'),
id='fields.E303',
),
@ -987,17 +987,19 @@ class ExplicitRelatedNameClashTests(SimpleTestCase):
expected = [
Error(
"Reverse accessor for 'Model.rel' clashes with field name 'Target.clash'.",
hint=("Rename field 'Target.clash', or add/change "
"a related_name argument to the definition "
"for field 'Model.rel'."),
hint=(
"Rename field 'Target.clash', or add/change a related_name "
"argument to the definition for field 'Model.rel'."
),
obj=Model._meta.get_field('rel'),
id='fields.E302',
),
Error(
"Reverse query name for 'Model.rel' clashes with field name 'Target.clash'.",
hint=("Rename field 'Target.clash', or add/change "
"a related_name argument to the definition "
"for field 'Model.rel'."),
hint=(
"Rename field 'Target.clash', or add/change a related_name "
"argument to the definition for field 'Model.rel'."
),
obj=Model._meta.get_field('rel'),
id='fields.E303',
),
@ -1085,8 +1087,10 @@ class ExplicitRelatedQueryNameClashTests(SimpleTestCase):
expected = [
Error(
"Reverse query name for 'Model.rel' clashes with field name 'Target.clash'.",
hint=("Rename field 'Target.clash', or add/change a related_name "
"argument to the definition for field 'Model.rel'."),
hint=(
"Rename field 'Target.clash', or add/change a related_name "
"argument to the definition for field 'Model.rel'."
),
obj=Model._meta.get_field('rel'),
id='fields.E303',
),
@ -1106,15 +1110,19 @@ class SelfReferentialM2MClashTests(SimpleTestCase):
expected = [
Error(
"Reverse accessor for 'Model.first_m2m' clashes with reverse accessor for 'Model.second_m2m'.",
hint=("Add or change a related_name argument to the definition "
"for 'Model.first_m2m' or 'Model.second_m2m'."),
hint=(
"Add or change a related_name argument to the definition "
"for 'Model.first_m2m' or 'Model.second_m2m'."
),
obj=Model._meta.get_field('first_m2m'),
id='fields.E304',
),
Error(
"Reverse accessor for 'Model.second_m2m' clashes with reverse accessor for 'Model.first_m2m'.",
hint=("Add or change a related_name argument to the definition "
"for 'Model.second_m2m' or 'Model.first_m2m'."),
hint=(
"Add or change a related_name argument to the definition "
"for 'Model.second_m2m' or 'Model.first_m2m'."
),
obj=Model._meta.get_field('second_m2m'),
id='fields.E304',
),
@ -1129,9 +1137,10 @@ class SelfReferentialM2MClashTests(SimpleTestCase):
expected = [
Error(
"Reverse accessor for 'Model.model_set' clashes with field name 'Model.model_set'.",
hint=("Rename field 'Model.model_set', or add/change "
"a related_name argument to the definition "
"for field 'Model.model_set'."),
hint=(
"Rename field 'Model.model_set', or add/change a related_name "
"argument to the definition for field 'Model.model_set'."
),
obj=Model._meta.get_field('model_set'),
id='fields.E302',
),
@ -1146,8 +1155,10 @@ class SelfReferentialM2MClashTests(SimpleTestCase):
expected = [
Error(
"Reverse query name for 'Model.model' clashes with field name 'Model.model'.",
hint=("Rename field 'Model.model', or add/change a related_name "
"argument to the definition for field 'Model.model'."),
hint=(
"Rename field 'Model.model', or add/change a related_name "
"argument to the definition for field 'Model.model'."
),
obj=Model._meta.get_field('model'),
id='fields.E303',
),
@ -1157,22 +1168,25 @@ class SelfReferentialM2MClashTests(SimpleTestCase):
def test_clash_under_explicit_related_name(self):
class Model(models.Model):
clash = models.IntegerField()
m2m = models.ManyToManyField("self",
symmetrical=False, related_name='clash')
m2m = models.ManyToManyField("self", symmetrical=False, related_name='clash')
errors = Model.check()
expected = [
Error(
"Reverse accessor for 'Model.m2m' clashes with field name 'Model.clash'.",
hint=("Rename field 'Model.clash', or add/change a related_name "
"argument to the definition for field 'Model.m2m'."),
hint=(
"Rename field 'Model.clash', or add/change a related_name "
"argument to the definition for field 'Model.m2m'."
),
obj=Model._meta.get_field('m2m'),
id='fields.E302',
),
Error(
"Reverse query name for 'Model.m2m' clashes with field name 'Model.clash'.",
hint=("Rename field 'Model.clash', or add/change a related_name "
"argument to the definition for field 'Model.m2m'."),
hint=(
"Rename field 'Model.clash', or add/change a related_name "
"argument to the definition for field 'Model.m2m'."
),
obj=Model._meta.get_field('m2m'),
id='fields.E303',
),
@ -1181,10 +1195,8 @@ class SelfReferentialM2MClashTests(SimpleTestCase):
def test_valid_model(self):
class Model(models.Model):
first = models.ManyToManyField("self",
symmetrical=False, related_name='first_accessor')
second = models.ManyToManyField("self",
symmetrical=False, related_name='second_accessor')
first = models.ManyToManyField("self", symmetrical=False, related_name='first_accessor')
second = models.ManyToManyField("self", symmetrical=False, related_name='second_accessor')
errors = Model.check()
self.assertEqual(errors, [])
@ -1201,9 +1213,11 @@ class SelfReferentialFKClashTests(SimpleTestCase):
expected = [
Error(
"Reverse accessor for 'Model.model_set' clashes with field name 'Model.model_set'.",
hint=("Rename field 'Model.model_set', or add/change "
"a related_name argument to the definition "
"for field 'Model.model_set'."),
hint=(
"Rename field 'Model.model_set', or add/change "
"a related_name argument to the definition "
"for field 'Model.model_set'."
),
obj=Model._meta.get_field('model_set'),
id='fields.E302',
),
@ -1218,9 +1232,10 @@ class SelfReferentialFKClashTests(SimpleTestCase):
expected = [
Error(
"Reverse query name for 'Model.model' clashes with field name 'Model.model'.",
hint=("Rename field 'Model.model', or add/change "
"a related_name argument to the definition "
"for field 'Model.model'."),
hint=(
"Rename field 'Model.model', or add/change a related_name "
"argument to the definition for field 'Model.model'."
),
obj=Model._meta.get_field('model'),
id='fields.E303',
),
@ -1236,17 +1251,19 @@ class SelfReferentialFKClashTests(SimpleTestCase):
expected = [
Error(
"Reverse accessor for 'Model.foreign' clashes with field name 'Model.clash'.",
hint=("Rename field 'Model.clash', or add/change "
"a related_name argument to the definition "
"for field 'Model.foreign'."),
hint=(
"Rename field 'Model.clash', or add/change a related_name "
"argument to the definition for field 'Model.foreign'."
),
obj=Model._meta.get_field('foreign'),
id='fields.E302',
),
Error(
"Reverse query name for 'Model.foreign' clashes with field name 'Model.clash'.",
hint=("Rename field 'Model.clash', or add/change "
"a related_name argument to the definition "
"for field 'Model.foreign'."),
hint=(
"Rename field 'Model.clash', or add/change a related_name "
"argument to the definition for field 'Model.foreign'."
),
obj=Model._meta.get_field('foreign'),
id='fields.E303',
),
@ -1402,15 +1419,17 @@ class M2mThroughFieldsTests(SimpleTestCase):
errors = field.check(from_model=Event)
expected = [
Error(
("'Invitation.invitee' is not a foreign key to 'Event'."),
"'Invitation.invitee' is not a foreign key to 'Event'.",
hint="Did you mean one of the following foreign keys to 'Event': event?",
obj=field,
id='fields.E339'),
id='fields.E339',
),
Error(
("'Invitation.event' is not a foreign key to 'Fan'."),
"'Invitation.event' is not a foreign key to 'Fan'.",
hint="Did you mean one of the following foreign keys to 'Fan': invitee, inviter?",
obj=field,
id='fields.E339'),
id='fields.E339',
),
]
self.assertEqual(expected, errors)
@ -1441,12 +1460,14 @@ class M2mThroughFieldsTests(SimpleTestCase):
"The intermediary model 'invalid_models_tests.Invitation' has no field 'invalid_field_1'.",
hint="Did you mean one of the following foreign keys to 'Event': event?",
obj=field,
id='fields.E338'),
id='fields.E338',
),
Error(
"The intermediary model 'invalid_models_tests.Invitation' has no field 'invalid_field_2'.",
hint="Did you mean one of the following foreign keys to 'Fan': invitee, inviter?",
obj=field,
id='fields.E338'),
id='fields.E338',
),
]
self.assertEqual(expected, errors)
@ -1473,8 +1494,7 @@ class M2mThroughFieldsTests(SimpleTestCase):
"Field specifies 'through_fields' but does not provide the names "
"of the two link fields that should be used for the relation "
"through model 'invalid_models_tests.Invitation'.",
hint=("Make sure you specify 'through_fields' as "
"through_fields=('field1', 'field2')"),
hint="Make sure you specify 'through_fields' as through_fields=('field1', 'field2')",
obj=field,
id='fields.E337')]
self.assertEqual(expected, errors)

View File

@ -40,7 +40,6 @@ class ModelValidationTest(SimpleTestCase):
"The 'on_post_init' function was connected to the 'post_init' "
"signal with a lazy reference to the 'missing-app.Model' "
"sender, which has not been installed.",
hint=None,
obj='model_validation.tests',
id='signals.E001',
),
@ -48,7 +47,6 @@ class ModelValidationTest(SimpleTestCase):
"An instance of the 'OnPostInit' class was connected to "
"the 'post_init' signal with a lazy reference to the "
"'missing-app.Model' sender, which has not been installed.",
hint=None,
obj='model_validation.tests',
id='signals.E001',
)

View File

@ -1239,17 +1239,17 @@ class OrderingCheckTests(CheckTestCase):
self.assertIsInvalid(
ValidationTestModelAdmin, ValidationTestModel,
"The value of 'ordering' must be a list or tuple.",
'admin.E031')
'admin.E031'
)
class ValidationTestModelAdmin(ModelAdmin):
ordering = ('non_existent_field',)
self.assertIsInvalid(
ValidationTestModelAdmin,
ValidationTestModel, (
"The value of 'ordering[0]' refers to 'non_existent_field', "
"which is not an attribute of 'modeladmin.ValidationTestModel'."
), 'admin.E033'
ValidationTestModelAdmin, ValidationTestModel,
"The value of 'ordering[0]' refers to 'non_existent_field', "
"which is not an attribute of 'modeladmin.ValidationTestModel'.",
'admin.E033'
)
def test_random_marker_not_alone(self):
@ -1258,10 +1258,11 @@ class OrderingCheckTests(CheckTestCase):
self.assertIsInvalid(
ValidationTestModelAdmin, ValidationTestModel,
("The value of 'ordering' has the random ordering marker '?', but contains "
"other fields as well."),
"The value of 'ordering' has the random ordering marker '?', but contains "
"other fields as well.",
'admin.E032',
hint='Either remove the "?", or remove the other fields.')
hint='Either remove the "?", or remove the other fields.'
)
def test_valid_random_marker_case(self):
class ValidationTestModelAdmin(ModelAdmin):
@ -1288,7 +1289,8 @@ class ListSelectRelatedCheckTests(CheckTestCase):
class ValidationTestModelAdmin(ModelAdmin):
list_select_related = 1
self.assertIsInvalid(ValidationTestModelAdmin, ValidationTestModel,
self.assertIsInvalid(
ValidationTestModelAdmin, ValidationTestModel,
"The value of 'list_select_related' must be a boolean, tuple or list.",
'admin.E117')

View File

@ -149,8 +149,6 @@ class ProxyModelTests(TestCase):
expected = [
checks.Error(
"Proxy model 'NoNewFields' contains model fields.",
hint=None,
obj=None,
id='models.E017',
)
]

View File

@ -44,9 +44,8 @@ class CurrentSiteManagerChecksTests(SimpleTestCase):
errors = InvalidArticle.check()
expected = [
checks.Error(
("CurrentSiteManager could not find a field named "
"'places_this_article_should_appear'."),
hint=None,
"CurrentSiteManager could not find a field named "
"'places_this_article_should_appear'.",
obj=InvalidArticle.on_site,
id='sites.E001',
)
@ -62,8 +61,8 @@ class CurrentSiteManagerChecksTests(SimpleTestCase):
errors = ConfusedArticle.check()
expected = [
checks.Error(
"CurrentSiteManager cannot use 'ConfusedArticle.site' as it is not a ForeignKey or ManyToManyField.",
hint=None,
"CurrentSiteManager cannot use 'ConfusedArticle.site' as it is "
"not a ForeignKey or ManyToManyField.",
obj=ConfusedArticle.on_site,
id='sites.E002',
)