MCPcopy
hub / github.com/django/django / run_select_for_update

Method run_select_for_update

tests/select_for_update/tests.py:543–564  ·  view source on GitHub ↗

Utility method that runs a SELECT FOR UPDATE against all Person instances. After the select_for_update, it attempts to update the name of the only record, save, and commit. This function expects to run in a separate thread.

(self, status, **kwargs)

Source from the content-addressed store, hash-verified

541 list(Person.objects.order_by("pk").select_for_update()[1:2])
542
543 def run_select_for_update(self, status, **kwargs):
544 """
545 Utility method that runs a SELECT FOR UPDATE against all
546 Person instances. After the select_for_update, it attempts
547 to update the name of the only record, save, and commit.
548
549 This function expects to run in a separate thread.
550 """
551 status.append("started")
552 try:
553 # We need to enter transaction management again, as this is done on
554 # per-thread basis
555 with transaction.atomic():
556 person = Person.objects.select_for_update(**kwargs).get()
557 person.name = "Fred"
558 person.save()
559 except (DatabaseError, Person.DoesNotExist) as e:
560 status.append(e)
561 finally:
562 # This method is run in a separate thread. It uses its own
563 # database connection. Close it without waiting for the GC.
564 connection.close()
565
566 @skipUnlessDBFeature("has_select_for_update")
567 @skipUnlessDBFeature("supports_transactions")

Callers

nothing calls this directly

Calls 5

select_for_updateMethod · 0.80
appendMethod · 0.45
getMethod · 0.45
saveMethod · 0.45
closeMethod · 0.45

Tested by

no test coverage detected