#35060: Make Model.save() arguments keyword-only
-------------------------------------+-------------------------------------
Reporter: Jacob | Owner: Jacob Walls
Walls |
Type: | Status: assigned
Cleanup/optimization |
Component: | Version: dev
Uncategorized |
Severity: Normal | Keywords:
Triage Stage: | Has patch: 0
Unreviewed |
Needs documentation: 0 | Needs tests: 0
Patch needs improvement: 0 | Easy pickings: 0
UI/UX: 0 |
-------------------------------------+-------------------------------------
Following this forum [https://forum.djangoproject.com/t/hook-for-
extending-update-fields-in-save-overrides/26040/5 discussion], I suggest
making `Model.save()` accept keyword arguments only (following a
deprecation period, of course).
For users who need to patch `update_fields` in an overridden `save()`, it
would be much simpler to only have to drill into `**kwargs` and not also
drill into (and check the length of) `*args` first.
Implementing this ticket would alleviate a small part of a current
inconsistency in the advice for overridding save(). In one portion, the
implementer is advised to pass through both `*args` and `**kwargs`:
{{{
It's also important that you pass through the arguments that can be
passed to the model method -- that's what the ``*args, **kwargs`` bit
does. Django will, from time to time, extend the capabilities of
built-in model methods, adding new arguments. If you use ``*args,
**kwargs`` in your method definitions, you are guaranteed that your
code will automatically support those arguments when they are added.
}}}
Then, an example tailored to passing through `update_fields`, passes
through *no* variadic arguments:
{{{
def save(
self, force_insert=False, force_update=False, using=None,
update_fields=None
):
}}}
We could make the situation better by taking away swallowed `*args` as a
vector for bugs.
--
Ticket URL: <https://code.djangoproject.com/ticket/35060>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.
--
You received this message because you are subscribed to the Google Groups
"Django updates" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To view this discussion on the web visit
https://groups.google.com/d/msgid/django-updates/0107018c930b9bc5-6a94792b-a17e-40b9-adec-0dc4184d8059-000000%40eu-central-1.amazonses.com.