diff --git a/django/contrib/contenttypes/generic.py b/django/contrib/contenttypes/generic.py index 3e132bb3a4f..cc03f799f3e 100644 --- a/django/contrib/contenttypes/generic.py +++ b/django/contrib/contenttypes/generic.py @@ -137,9 +137,6 @@ class GenericForeignKey(six.with_metaclass(RenameGenericForeignKeyMethods)): return rel_obj def __set__(self, instance, value): - if instance is None: - raise AttributeError("%s must be accessed via instance" % self.related.opts.object_name) - ct = None fk = None if value is not None: @@ -280,9 +277,6 @@ class ReverseGenericRelatedObjectsDescriptor(object): return manager def __set__(self, instance, value): - if instance is None: - raise AttributeError("Manager must be accessed via instance") - manager = self.__get__(instance) manager.clear() for obj in value: diff --git a/django/db/models/fields/related.py b/django/db/models/fields/related.py index e85b3301bf4..256c3e0f614 100644 --- a/django/db/models/fields/related.py +++ b/django/db/models/fields/related.py @@ -206,9 +206,6 @@ class SingleRelatedObjectDescriptor(six.with_metaclass(RenameRelatedObjectDescri return rel_obj def __set__(self, instance, value): - if instance is None: - raise AttributeError("%s must be accessed via instance" % self.related.opts.object_name) - # The similarity of the code below to the code in # ReverseSingleRelatedObjectDescriptor is annoying, but there's a bunch # of small differences that would make a common base class convoluted. @@ -312,9 +309,6 @@ class ReverseSingleRelatedObjectDescriptor(six.with_metaclass(RenameRelatedObjec return rel_obj def __set__(self, instance, value): - if instance is None: - raise AttributeError("%s must be accessed via instance" % self.field.name) - # If null=True, we can assign null here, but otherwise the value needs # to be an instance of the related class. if value is None and self.field.null == False: @@ -384,9 +378,6 @@ class ForeignRelatedObjectsDescriptor(object): return self.related_manager_cls(instance) def __set__(self, instance, value): - if instance is None: - raise AttributeError("Manager must be accessed via instance") - manager = self.__get__(instance) # If the foreign key can support nulls, then completely clear the related set. # Otherwise, just move the named objects into the set. @@ -767,9 +758,6 @@ class ManyRelatedObjectsDescriptor(object): return manager def __set__(self, instance, value): - if instance is None: - raise AttributeError("Manager must be accessed via instance") - if not self.related.field.rel.through._meta.auto_created: opts = self.related.field.rel.through._meta raise AttributeError("Cannot set values on a ManyToManyField which specifies an intermediary model. Use %s.%s's Manager instead." % (opts.app_label, opts.object_name)) @@ -824,9 +812,6 @@ class ReverseManyRelatedObjectsDescriptor(object): return manager def __set__(self, instance, value): - if instance is None: - raise AttributeError("Manager must be accessed via instance") - if not self.field.rel.through._meta.auto_created: opts = self.field.rel.through._meta raise AttributeError("Cannot set values on a ManyToManyField which specifies an intermediary model. Use %s.%s's Manager instead." % (opts.app_label, opts.object_name))