16470: Fixes the last deprecation warnings.
authorLucas Di Pentima <lucas@di-pentima.com.ar>
Fri, 24 Jul 2020 20:12:27 +0000 (17:12 -0300)
committerLucas Di Pentima <lucas@di-pentima.com.ar>
Mon, 24 Aug 2020 15:21:27 +0000 (12:21 -0300)
It turned out that .lock!() is an ActiveRecord method, and I was confusing it
with Container::lock and ContainerRequest::lock.
Both lock! and with_lock methods need the record to be persisted or reloaded
explicitly.

Arvados-DCO-1.1-Signed-off-by: Lucas Di Pentima <lucas@di-pentima.com.ar>

services/api/app/models/container_request.rb

index 77536eee4f28f53a2acae66cc90d647967ff6b51..16b4973216b230f3193e194527a66db709ab5c90 100644 (file)
@@ -123,10 +123,10 @@ class ContainerRequest < ArvadosModel
     while true
       # get container lock first, then lock current container request
       # (same order as Container#handle_completed). Locking always
-      # reloads the Container and ContainerRequest records.
+      # requires explicit Container and ContainerRequest records reload.
       c = Container.find_by_uuid(container_uuid)
-      c.lock! if !c.nil?
-      self.lock!
+      c.reload.lock! if !c.nil?
+      self.reload.lock!
 
       if !c.nil? && container_uuid != c.uuid
         # After locking, we've noticed a race, the container_uuid is
@@ -263,7 +263,7 @@ class ContainerRequest < ArvadosModel
     if state_changed? and state == Committed and container_uuid.nil?
       while true
         c = Container.resolve(self)
-        c.lock!
+        c.reload.lock!
         if c.state == Container::Cancelled
           # Lost a race, we have a lock on the container but the
           # container was cancelled in a different request, restart