Skip to content

Commit

Permalink
Fixed django#18002 -- Fixed typo in attribute name in ReverseSingleRe…
Browse files Browse the repository at this point in the history
…latedObjectDescriptor.

git-svn-id: http://code.djangoproject.com/svn/django/trunk@17904 bcc190cf-cafb-0310-a4f2-bffc1f526a37
  • Loading branch information
claudep committed Apr 12, 2012
1 parent 844e56e commit 2cd5160
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 1 deletion.
2 changes: 1 addition & 1 deletion django/db/models/fields/related.py
Original file line number Diff line number Diff line change
Expand Up @@ -364,7 +364,7 @@ def __get__(self, instance, instance_type=None):

def __set__(self, instance, value):
if instance is None:
raise AttributeError("%s must be accessed via instance" % self._field.name)
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.
Expand Down
4 changes: 4 additions & 0 deletions tests/regressiontests/many_to_one_regress/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,10 @@ def test_fk_assignment_and_related_object_cache(self):
self.assertRaises(ValueError, Child, name='xyzzy', parent=None)
self.assertRaises(ValueError, Child.objects.create, name='xyzzy', parent=None)

# Trying to assign to unbound attribute raises AttributeError
self.assertRaisesRegexp(AttributeError, "must be accessed via instance",
Child.parent.__set__, None, p)

# Creation using keyword argument should cache the related object.
p = Parent.objects.get(name="Parent")
c = Child(parent=p)
Expand Down

0 comments on commit 2cd5160

Please sign in to comment.