﻿id	summary	reporter	owner	description	type	status	component	version	severity	resolution	keywords	cc	stage	has_patch	needs_docs	needs_tests	needs_better_patch	easy	ui_ux
28742	get/set on a OneToOneField produces AttributeError	Faidon Liambotis	Paulo	"On a sample empty project (mysite) with a sample empty app (myapp) with these models:

{{{
from django.db import models
 
class Place(models.Model):
    name = models.CharField(max_length=50)
    address = models.CharField(max_length=80)
 
class Restaurant(models.Model):
    place = models.OneToOneField(Place)
    serves_hot_dogs = models.BooleanField(default=False)
    serves_pizza = models.BooleanField(default=False)
}}}

Executing this, works just fine:
{{{
p = Place()
p.restaurant = None
}}}

But this:
{{{
p = Place()
r = getattr(p, 'restaurant', None)
p.restaurant = None
}}}

…raises an AttributeError:
{{{
AttributeError                            Traceback (most recent call last)
<ipython-input-4-c4df23702cac> in <module>()
----> 1 p.restaurant = None
 
.../lib/python3.5/site-packages/django/db/models/fields/related_descriptors.py in __set__(self, instance, value)
    435             else:
    436                 delattr(instance, self.cache_name)
--> 437                 setattr(rel_obj, self.related.field.name, None)
    438         elif not isinstance(value, self.related.related_model):
    439             # An object must be an instance of the related class.
 
AttributeError: 'NoneType' object has no attribute 'place'
}}}

The above is with Python 3.5.3 and Django 1.11.6, although user ""knbk"" on #django said that they reproduced it in master."	Bug	closed	Database layer (models, ORM)	1.11	Normal	fixed			Accepted	1	0	0	0	0	0
