[Django] #26027: Django model __init__ silently accepts parameters that are also a non-settable property

6 views
Skip to first unread message

Django

unread,
Jan 3, 2016, 10:40:30 AM1/3/16
to django-...@googlegroups.com
#26027: Django model __init__ silently accepts parameters that are also a non-
settable property
-------------------------------+--------------------
Reporter: vanschelven | Owner: nobody
Type: Uncategorized | Status: new
Component: Uncategorized | Version: 1.8
Severity: Normal | Keywords:
Triage Stage: Unreviewed | Has patch: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------+--------------------
When passing a keyword argument to a Django model instantiation, when the
keyword argument also happens to be a non-settable property, this keyword
argument is silently swallowed and nothing happens.

This may hide hard-to-track errors. It's also inconsistent (arguments
which are not non-settable properties give an error like ".... is an
invalid keyword argument for this function")

This seems to have been introduced in ancient history:
https://github.com/django/django/commit/1fc3b3229a9b137f05a0a49bdc726f8c91317174

However, looking at the tests that were introduced as a part of that
particular commit I don't actually see a reason why the try/except block
would be necessary in the first place (the included tests actually refer
the opposite scenario, the one were a setter _is_ available). In fact,
looking at the original test, this particular bug could simply be revealed
by putting something like

{{{
a = Person(full_name = 'Paul McCartney')
}}}

In an assertRaises.

(As of the status quo, this silently does nothing with the value "Paul
McCartney")

I would have loved to do the work-proper to reveal the bug with tests; but
I don't have the time for that now - sorry about that.

--
Ticket URL: <https://code.djangoproject.com/ticket/26027>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.

Django

unread,
Jan 3, 2016, 11:07:59 AM1/3/16
to django-...@googlegroups.com
#26027: Django model __init__ silently accepts parameters that are also a non-
settable property
-------------------------------+--------------------------------------
Reporter: vanschelven | Owner: nobody
Type: Uncategorized | Status: closed
Component: Uncategorized | Version: 1.8
Severity: Normal | Resolution: duplicate
Keywords: | Triage Stage: Unreviewed
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0

Easy pickings: 0 | UI/UX: 0
-------------------------------+--------------------------------------
Changes (by knbk):

* status: new => closed
* needs_better_patch: => 0
* resolution: => duplicate
* needs_tests: => 0
* needs_docs: => 0


Comment:

Duplicate of #25910.

--
Ticket URL: <https://code.djangoproject.com/ticket/26027#comment:1>

Reply all
Reply to author
Forward
0 new messages