Code

Opened 5 years ago

Closed 5 years ago

#11749 closed (invalid)

QuerySet not autmatically evaluated on attribut update?

Reported by: gz Owned by: nobody
Component: Uncategorized Version: 1.1
Severity: Keywords: Database ORM QuerySet evaluation
Cc: gz Triage Stage: Unreviewed
Has patch: no Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: UI/UX:

Description

Not evaluating QuerySets manually by using list() gives strange results while trying to update a model in the list:

my_list = Model.objects.all()
my_list[order].some_attribute = 12
my_list[index].save() # some_attribute is not updated!
# with my_list = list(Model.objects.all()) it works tough

I don't know if this is really a bug or intended behaviour?

Attachments (0)

Change History (2)

comment:1 in reply to: ↑ description Changed 5 years ago by gz

  • Needs documentation unset
  • Needs tests unset
  • Patch needs improvement unset

Replying to gz:

Not evaluating QuerySets manually by using list() gives strange results while trying to update a model in the list:

my_list = Model.objects.all()
my_list[order].some_attribute = 12
my_list[index].save() # some_attribute is not updated!
# with my_list = list(Model.objects.all()) it works tough

I don't know if this is really a bug or intended behaviour?

order should be equal to index here, otherwise this example does not make sense

comment:2 Changed 5 years ago by ubernostrum

  • Resolution set to invalid
  • Status changed from new to closed

This is intended behavior; a QuerySet is not a list, and code which assumes it is will likely have difficulties.

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.