mirror of
https://github.com/django/django.git
synced 2025-11-07 07:15:35 +00:00
[1.11.x] Fixed #28269 -- Fixed Model.__init__() crash on models with a field that has an instance only descriptor.
Regression ind2a26c1a90. Backport ofed244199c7from master
This commit is contained in:
@@ -9,6 +9,13 @@ class Relation(models.Model):
|
||||
pass
|
||||
|
||||
|
||||
class InstanceOnlyDescriptor(object):
|
||||
def __get__(self, instance, cls=None):
|
||||
if instance is None:
|
||||
raise AttributeError('Instance only')
|
||||
return 1
|
||||
|
||||
|
||||
class AbstractPerson(models.Model):
|
||||
# DATA fields
|
||||
data_abstract = models.CharField(max_length=10)
|
||||
@@ -43,6 +50,8 @@ class AbstractPerson(models.Model):
|
||||
def test_property(self):
|
||||
return 1
|
||||
|
||||
test_instance_only_descriptor = InstanceOnlyDescriptor()
|
||||
|
||||
|
||||
class BasePerson(AbstractPerson):
|
||||
# DATA fields
|
||||
|
||||
@@ -276,4 +276,6 @@ class ParentListTests(SimpleTestCase):
|
||||
|
||||
class PropertyNamesTests(SimpleTestCase):
|
||||
def test_person(self):
|
||||
# Instance only descriptors don't appear in _property_names.
|
||||
self.assertEqual(AbstractPerson().test_instance_only_descriptor, 1)
|
||||
self.assertEqual(AbstractPerson._meta._property_names, frozenset(['pk', 'test_property']))
|
||||
|
||||
Reference in New Issue
Block a user