Fixed #29517 -- Rephrased error message when passing incorrect kwarg to model constructor

This commit is contained in:
Federico Bond 2018-06-25 09:30:58 +02:00 committed by Claude Paroz
parent 02cd16a7a0
commit 4c36414323
3 changed files with 3 additions and 3 deletions

View File

@ -481,7 +481,7 @@ class Model(metaclass=ModelBase):
except (AttributeError, FieldDoesNotExist):
pass
for kwarg in kwargs:
raise TypeError("'%s' is an invalid keyword argument for this function" % kwarg)
raise TypeError("%s() got an unexpected keyword argument '%s'" % (cls.__name__, list(kwargs)[0]))
super().__init__()
post_init.send(sender=cls, instance=self)

View File

@ -65,7 +65,7 @@ class ModelInstanceCreationTests(TestCase):
self.assertEqual(a.headline, 'Fourth article')
def test_cannot_create_instance_with_invalid_kwargs(self):
with self.assertRaisesMessage(TypeError, "'foo' is an invalid keyword argument for this function"):
with self.assertRaisesMessage(TypeError, "Article() got an unexpected keyword argument 'foo'"):
Article(
id=None,
headline='Some headline',

View File

@ -18,7 +18,7 @@ class PropertyTests(TestCase):
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"):
with self.assertRaisesMessage(TypeError, "Person() got an unexpected keyword argument 'full_name'"):
Person(full_name='Paul McCartney')
# But "full_name_2" has, and it can be used to initialize the class.