Skip to content

Lock TestJob.actual_device in transactions when possible

Igor Ponomarev requested to merge lock-testjob-actual-device into master

A lot of TestJob state modifications involve changing the state of its actual_device. Without locking it is possible for something else to modify the device state while the TestJob state is being modified.

To lock it pass select_related("actual_device") combined with select_for_update(). However, it is only possible to lock the actual_device when it is not NULL otherwise database will return error. To avoid this check that actual_device is not NULL. If a combination of id and actual_device__isnull=False was not found then return TestJob where id and actual_device__isnull=True. This will ensure that the Device will get locked if the TestJob has a device assigned to it.

Also review everywhere the TestJob state can be changed and add missing transactions and locks.

Merge request reports