Opened 10 months ago

Last modified 9 months ago

#22640 new Cleanup/optimization

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

Reported by: zsoldosp Owned by: nobody
Component: Database layer (models, ORM) Version: master
Severity: Normal Keywords:
Cc: Triage Stage: Accepted
Has patch: no Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no


Discovered while working on #18586

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

    def test_cannot_specify_same_field_with_args_and_kwargs_too(self):
            "'foo' is an invalid keyword argument for this function",
            None, # id
            'args based headline',
            headline='kwargs based headline',
            pub_date=datetime(2005, 7, 31),

Change History (3)

comment:1 Changed 10 months ago by timo

  • Needs documentation unset
  • Needs tests unset
  • Patch needs improvement unset

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 months ago by bmispelon

  • Triage Stage changed from Unreviewed to Accepted
  • Type changed from Bug to Cleanup/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 10 months ago by bmispelon (previous) (diff)

comment:3 Changed 9 months ago 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'"

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