You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@airflow.apache.org by po...@apache.org on 2022/03/11 17:25:53 UTC

[airflow] branch main updated: Avoid trying to kill container when it did not succeed for Docker (#22145)

This is an automated email from the ASF dual-hosted git repository.

potiuk pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/airflow.git


The following commit(s) were added to refs/heads/main by this push:
     new 03cdfe7  Avoid trying to kill container when it did not succeed for Docker (#22145)
03cdfe7 is described below

commit 03cdfe701bd52dc85572fe1ec5fd68d742775c8c
Author: Jarek Potiuk <ja...@potiuk.com>
AuthorDate: Fri Mar 11 18:25:13 2022 +0100

    Avoid trying to kill container when it did not succeed for Docker (#22145)
    
    When container cannot be created in Docker Operator and
    exception is raised, the on_kill method attempts to kill the
    container but since it is None, it fails with another exception
    
    ```
        self.cli.stop(self.container['Id'])
        TypeError: 'NoneType' object is not subscriptable
    ```
    
    and the original exception is swallowed.
    
    This PR avoids stopping the container if it has not been created.
---
 airflow/providers/docker/operators/docker.py | 3 +++
 1 file changed, 3 insertions(+)

diff --git a/airflow/providers/docker/operators/docker.py b/airflow/providers/docker/operators/docker.py
index 7e0cd3a..53dc5d9 100644
--- a/airflow/providers/docker/operators/docker.py
+++ b/airflow/providers/docker/operators/docker.py
@@ -406,6 +406,9 @@ class DockerOperator(BaseOperator):
     def on_kill(self) -> None:
         if self.cli is not None:
             self.log.info('Stopping docker container')
+            if self.container is None:
+                self.log.info('Not attempting to kill container as it was not created')
+                return
             self.cli.stop(self.container['Id'])
 
     def __get_tls_config(self) -> Optional[tls.TLSConfig]: