Code

Opened 4 years ago

Closed 4 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:

Description

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)
dict.update({'a':1})


Attachments (0)

Change History (1)

comment:1 Changed 4 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.

Add Comment

Modify Ticket

Change Properties
<Author field>
Action
as closed
as The resolution will be set. Next status will be 'closed'
The resolution will be deleted. Next status will be 'new'
Author


E-mail address and user name can be saved in the Preferences.

 
Note: See TracTickets for help on using tickets.