Opened 10 years ago

Closed 3 years ago

#22640 closed Cleanup/optimization (fixed)

Can create model instance with conflicting args and kwargs value for the same field

Reported by: Peter Zsoldos Owned by: Jacob Walls
Component: Database layer (models, ORM) Version: dev
Severity: Normal Keywords:
Cc: Triage Stage: Ready for checkin
Has patch: yes Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

Description (last modified by Anton Samarchyan)

Discovered while working on #18586

To reproduce it, add the following test (it's using tests.basic.models.Article)

    from django.utils import six
    def test_cannot_specify_same_field_with_args_and_kwargs_too(self):
            "__init__() got multiple values for argument 'headline'",
            None, # id
            'args based headline',
            headline='kwargs based headline',
            pub_date=datetime(2005, 7, 31),

Change History (7)

comment:1 Changed 10 years ago by Tim Graham

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.

comment:2 Changed 10 years ago by Baptiste Mispelon

Triage Stage: UnreviewedAccepted
Type: BugCleanup/optimization


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.



Last edited 4 years ago by Baptiste Mispelon (previous) (diff)

comment:3 Changed 10 years ago by Peter Zsoldos

Last edited 7 years ago by Anton Samarchyan (previous) (diff)

comment:4 Changed 7 years ago by Anton Samarchyan

Description: modified (diff)

comment:5 Changed 3 years ago by Jacob Walls

Has patch: set
Owner: changed from nobody to Jacob Walls
Status: newassigned

comment:6 Changed 3 years ago by Mariusz Felisiak

Triage Stage: AcceptedReady for checkin

comment:7 Changed 3 years ago by Mariusz Felisiak <felisiak.mariusz@…>

Resolution: fixed
Status: assignedclosed

In 73b1b225:

Fixed #22640 -- Raised TypeError when instantiating model with keyword and positional args for the same field.

Note: See TracTickets for help on using tickets.
Back to Top