diff options
| author | Joshua Phillips <jphillips@imap.cc> | 2016-01-21 16:49:40 +0000 |
|---|---|---|
| committer | Tim Graham <timograham@gmail.com> | 2016-01-22 13:27:11 -0500 |
| commit | 16baec5c8a24ea4bf1bfc27a4c8fea7d0ff4860f (patch) | |
| tree | 67d6927556a2aff74749ddfd8e43492b4f290feb | |
| parent | 4dc74371e3879a1a9eb5fd39702f5c4e70014629 (diff) | |
Fixed #25910 -- Rejected read-only property names in model constructors.
| -rw-r--r-- | django/db/models/base.py | 3 | ||||
| -rw-r--r-- | tests/properties/tests.py | 4 |
2 files changed, 6 insertions, 1 deletions
diff --git a/django/db/models/base.py b/django/db/models/base.py index 028367d584..333bee0c27 100644 --- a/django/db/models/base.py +++ b/django/db/models/base.py @@ -435,7 +435,8 @@ class Model(six.with_metaclass(ModelBase)): for prop in list(kwargs): try: if isinstance(getattr(self.__class__, prop), property): - setattr(self, prop, kwargs.pop(prop)) + setattr(self, prop, kwargs[prop]) + del kwargs[prop] except AttributeError: pass if kwargs: diff --git a/tests/properties/tests.py b/tests/properties/tests.py index 45443026a3..06e30e7b1f 100644 --- a/tests/properties/tests.py +++ b/tests/properties/tests.py @@ -18,6 +18,10 @@ class PropertyTests(TestCase): # The "full_name" property hasn't provided a "set" method. self.assertRaises(AttributeError, setattr, self.a, 'full_name', 'Paul McCartney') + # And cannot be used to initialize the class. + with self.assertRaisesMessage(TypeError, "'full_name' is an invalid keyword argument"): + Person(full_name='Paul McCartney') + # But "full_name_2" has, and it can be used to initialize the class. a2 = Person(full_name_2='Paul McCartney') a2.save() |
