Loading django/db/models/base.py +2 −1 Original line number Diff line number Diff line Loading @@ -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: Loading tests/properties/tests.py +4 −0 Original line number Diff line number Diff line Loading @@ -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() Loading Loading
django/db/models/base.py +2 −1 Original line number Diff line number Diff line Loading @@ -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: Loading
tests/properties/tests.py +4 −0 Original line number Diff line number Diff line Loading @@ -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() Loading