From a83c0775457ef4d4f261d47741440740cc9dd5ea Mon Sep 17 00:00:00 2001 From: Russell Keith-Magee Date: Tue, 28 Feb 2006 11:41:44 +0000 Subject: [PATCH] magic-removal: Refs #1407 -- Modified descriptor set method to ask forgiveness rather than permission. git-svn-id: http://code.djangoproject.com/svn/django/branches/magic-removal@2436 bcc190cf-cafb-0310-a4f2-bffc1f526a37 --- django/db/models/fields/related.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/django/db/models/fields/related.py b/django/db/models/fields/related.py index c7ae1a7ccd..d9e3d9c102 100644 --- a/django/db/models/fields/related.py +++ b/django/db/models/fields/related.py @@ -106,9 +106,9 @@ class SingleRelatedObjectDescriptor(object): def __set__(self, instance, value): # Set the value of the related field - if value: + try: val = getattr(value, self._field.rel.get_related_field().attname) - else: + except AttributeError: val = None setattr(instance, self._field.attname, val)