To reproduce it, add the following test (it's using
tests.basic.models.Article)
{{{#!python
def test_cannot_specify_same_field_with_args_and_kwargs_too(self):
six.assertRaisesRegex(
self,
TypeError,
"'foo' is an invalid keyword argument for this function",
Article,
None, # id
'args based headline',
headline='kwargs based headline',
pub_date=datetime(2005, 7, 31),
)
}}}
--
Ticket URL: <https://code.djangoproject.com/ticket/22640>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.
* needs_better_patch: => 0
* needs_tests: => 0
* needs_docs: => 0
Comment:
For what it's worth, I didn't realize there was any attempt to support
positional arguments in model instantiation (although it is tested, is it
documented anywhere?). May not be worth fixing, in my opinion.
--
Ticket URL: <https://code.djangoproject.com/ticket/22640#comment:1>
* type: Bug => Cleanup/optimization
* stage: Unreviewed => Accepted
Comment:
Hi,
From what I understand, `*args` instanciation is there for performance
reasons (see [1]).
I'll accept this ticket on the basis that it'd be nice to fix it but only
if it doesn't impact performance negatively.
Thanks.
[1]
--
Ticket URL: <https://code.djangoproject.com/ticket/22640#comment:2>
Comment (by zsoldosp):
Apologies, I've kept the wrong text message in the original test-repro,
that will have to change to "{{{__init__}}} got multiple values for
keyword argument 'headline'"
--
Ticket URL: <https://code.djangoproject.com/ticket/22640#comment:3>
Old description:
> Discovered while working on #18586
>
> To reproduce it, add the following test (it's using
> tests.basic.models.Article)
> {{{#!python
> def test_cannot_specify_same_field_with_args_and_kwargs_too(self):
> six.assertRaisesRegex(
> self,
> TypeError,
> "'foo' is an invalid keyword argument for this function",
> Article,
> None, # id
> 'args based headline',
> headline='kwargs based headline',
> pub_date=datetime(2005, 7, 31),
> )
> }}}
New description:
Discovered while working on #18586
To reproduce it, add the following test (it's using
tests.basic.models.Article)
{{{#!python
from django.utils import six
def test_cannot_specify_same_field_with_args_and_kwargs_too(self):
six.assertRaisesRegex(
self,
TypeError,
"__init__() got multiple values for argument 'headline'",
Article,
None, # id
'args based headline',
headline='kwargs based headline',
pub_date=datetime(2005, 7, 31),
)
}}}
--
--
Ticket URL: <https://code.djangoproject.com/ticket/22640#comment:4>
* owner: nobody => Jacob Walls
* status: new => assigned
* has_patch: 0 => 1
Comment:
[https://github.com/django/django/pull/14059 PR]
--
Ticket URL: <https://code.djangoproject.com/ticket/22640#comment:5>
* stage: Accepted => Ready for checkin
--
Ticket URL: <https://code.djangoproject.com/ticket/22640#comment:6>
* status: assigned => closed
* resolution: => fixed
Comment:
In [changeset:"73b1b225ce1a3318d4478f90cc0db0a260aba3aa" 73b1b225]:
{{{
#!CommitTicketReference repository=""
revision="73b1b225ce1a3318d4478f90cc0db0a260aba3aa"
Fixed #22640 -- Raised TypeError when instantiating model with keyword and
positional args for the same field.
}}}
--
Ticket URL: <https://code.djangoproject.com/ticket/22640#comment:7>