1. Home
  2. Computer Science MCQs
  3. Django
  4. In Django, what does the select_for_update method do?

Added 28 Apr 2024

In Django, what does the select_for_update method do?

  1. Retrieves related objects after the main query is executed
  2. Locks selected rows in the database to prevent concurrent updates Correct answer
  3. Performs a raw SQL query
  4. Filters query results based on a condition

Correct answer

B. Locks selected rows in the database to prevent concurrent updates

16 views

MCQSEXAM

Explanation

select_for_update() locks the selected rows until the transaction ends, so other transactions cannot change them in the meantime. It generates SELECT ... FOR UPDATE and must be used inside transaction.atomic().

It prevents race conditions in operations like balance updates.

Practise more Computer Science MCQs with answers and explanations on MCQsExam.com.

Doubts & discussion

Not sure why the answer is B? Ask here and get an explanation.

Ask a doubt about this MCQ

Shown after review. No links please.

More Django MCQs

Practise all Django MCQs

Similar MCQs