commit 6454ba57324065129588d4a1a9485c7ca20c52e2
Author: Joshua Phillips <jphillips@imap.cc>
Date: Thu Jan 21 16:49:40 2016 +0000
Don't accept read-only property names in model constructors
diff --git a/django/db/models/base.py b/django/db/models/base.py
index 028367d..333bee0 100644
a
|
b
|
class Model(six.with_metaclass(ModelBase)):
|
435 | 435 | for prop in list(kwargs): |
436 | 436 | try: |
437 | 437 | if isinstance(getattr(self.__class__, prop), property): |
438 | | setattr(self, prop, kwargs.pop(prop)) |
| 438 | setattr(self, prop, kwargs[prop]) |
| 439 | del kwargs[prop] |
439 | 440 | except AttributeError: |
440 | 441 | pass |
441 | 442 | if kwargs: |
diff --git a/tests/properties/tests.py b/tests/properties/tests.py
index 4544302..c998c15 100644
a
|
b
|
class PropertyTests(TestCase):
|
18 | 18 | # The "full_name" property hasn't provided a "set" method. |
19 | 19 | self.assertRaises(AttributeError, setattr, self.a, 'full_name', 'Paul McCartney') |
20 | 20 | |
| 21 | # And cannot be used to initialize the class. |
| 22 | self.assertRaises(TypeError, Person, full_name='Paul McCartney') |
| 23 | |
21 | 24 | # But "full_name_2" has, and it can be used to initialize the class. |
22 | 25 | a2 = Person(full_name_2='Paul McCartney') |
23 | 26 | a2.save() |