Opened 5 years ago

Closed 5 years ago

#14197 closed (invalid)

.update() doesn't work on model_to_dict(model_instance)

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


The following doesn't work:

from django.forms import model_to_dict
dict = model_to_dict(model_instance).update({'a':1})

whereas this does:

from django.forms import model_to_dict
dict = model_to_dict(model_instance)

Change History (1)

comment:1 Changed 5 years ago by lukeplant

  • Needs documentation unset
  • Needs tests unset
  • Patch needs improvement unset
  • Resolution set to invalid
  • Status changed from new to closed

"doesn't work" isn't helpful, since we don't know what you expect to happen. I expect the first one to do something different from the second, i.e. the first will end up with dict == None, since the update method of dict instances returns None. And that is what happens. This is Python behaviour, and nothing to do with the Django function model_to_dict.

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