diff options
| author | Claude Paroz <claude@2xlibre.net> | 2012-04-12 20:23:41 +0000 |
|---|---|---|
| committer | Claude Paroz <claude@2xlibre.net> | 2012-04-12 20:23:41 +0000 |
| commit | 2cd516002d43cdc09741618f0a0db047ee6d78fd (patch) | |
| tree | c9f459257cd7bd897f645dce493fcfb9cff9b344 | |
| parent | 844e56e21aa45a4bf1c549129e46f7d7959c74d8 (diff) | |
Fixed #18002 -- Fixed typo in attribute name in ReverseSingleRelatedObjectDescriptor.
git-svn-id: http://code.djangoproject.com/svn/django/trunk@17904 bcc190cf-cafb-0310-a4f2-bffc1f526a37
| -rw-r--r-- | django/db/models/fields/related.py | 2 | ||||
| -rw-r--r-- | tests/regressiontests/many_to_one_regress/tests.py | 4 |
2 files changed, 5 insertions, 1 deletions
diff --git a/django/db/models/fields/related.py b/django/db/models/fields/related.py index fbb40d9175..a16f9553c6 100644 --- a/django/db/models/fields/related.py +++ b/django/db/models/fields/related.py @@ -364,7 +364,7 @@ class ReverseSingleRelatedObjectDescriptor(object): 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. diff --git a/tests/regressiontests/many_to_one_regress/tests.py b/tests/regressiontests/many_to_one_regress/tests.py index 9e04fb4542..481a037139 100644 --- a/tests/regressiontests/many_to_one_regress/tests.py +++ b/tests/regressiontests/many_to_one_regress/tests.py @@ -58,6 +58,10 @@ class ManyToOneRegressionTests(TestCase): 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) |
