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)
| 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") |
nothing calls this directly
no test coverage detected