Opened 9 years ago

Closed 9 years ago

#26027 closed Uncategorized (duplicate)

Django model __init__ silently accepts parameters that are also a non-settable property

Reported by: Klaas van Schelven Owned by: nobody
Component: Uncategorized Version: 1.8
Severity: Normal Keywords:
Cc: Triage Stage: Unreviewed
Has patch: no Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

Description

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.

Change History (1)

comment:1 by Marten Kenbeek, 9 years ago

Resolution: duplicate
Status: newclosed

Duplicate of #25910.

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