From f6d53c2e420dca43f5bb647a18442b4903be8909 Mon Sep 17 00:00:00 2001 From: Jarek Potiuk Date: Thu, 10 Mar 2022 13:53:46 +0100 Subject: [PATCH] Avoid trying to kill container when it did not succeed for Docker 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 7e0cd3ac49501..53dc5d92dea8d 100644 --- a/airflow/providers/docker/operators/docker.py +++ b/airflow/providers/docker/operators/docker.py @@ -406,6 +406,9 @@ def format_command(command: Union[str, List[str]]) -> Union[List[str], str]: 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]: