#27118: update_or_create silently ignores mismatching field names in defaults
----------------------------------------------+--------------------
Reporter: brighters | Owner: nobody
Type: Bug | Status: new
Component: Database layer (models, ORM) | Version: 1.9
Severity: Normal | Keywords:
Triage Stage: Unreviewed | Has patch: 0
Easy pickings: 0 | UI/UX: 0
----------------------------------------------+--------------------
I'm not sure if this intended behaviour or an issue.
I came across this issue using the update_or_create method. I was passing
a set of defaults where one of the keys did not match with a field on the
model. When called in an update scenario the method worked and returned
the updated object and False, updating the model fields which matched with
the keywords provided in the defaults parameter. But in a create scenario
I got a "TypeError: '[incorrect_field_name]' is an invalid keyword
argument for this function.". My test coverage was a little lacking as it
only covered update scenarios, so I only came across the issue in
production in a create scenario.
I presume this is because the setattr method still runs successfully
against the model object, even if the keyword in defaults does not
correspond to a model field?
{{{
query.py
for k, v in six.iteritems(defaults):
setattr(obj, k, v)
}}}
--
Ticket URL: <https://code.djangoproject.com/ticket/27118>
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 post to this group, send email to [email protected].
To view this discussion on the web visit
https://groups.google.com/d/msgid/django-updates/052.a509fdc868e47e1a9d3db1865d859650%40djangoproject.com.
For more options, visit https://groups.google.com/d/optout.