From 5e32de343963baa23ffe170d97944a49534f8f4a Mon Sep 17 00:00:00 2001 From: retornam Date: Wed, 4 Mar 2020 19:29:29 -0800 Subject: [PATCH] [AIRFLOW-4363] Fix JSON encoding error From the docker-py code comments for APIClient pull, the decode parameter should be set to True, when the stream parameter is also set to True. This will allow decoding JSON data returned from the docker registry server into dicts Signed-off-by: Raymond Etornam --- airflow/providers/docker/operators/docker.py | 2 +- tests/providers/docker/operators/test_docker.py | 3 ++- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/airflow/providers/docker/operators/docker.py b/airflow/providers/docker/operators/docker.py index 2216d925ed42d0..b02801aab034a6 100644 --- a/airflow/providers/docker/operators/docker.py +++ b/airflow/providers/docker/operators/docker.py @@ -275,7 +275,7 @@ def execute(self, context): # Pull the docker image if `force_pull` is set or image does not exist locally if self.force_pull or not self.cli.images(name=self.image): self.log.info('Pulling docker image %s', self.image) - for line in self.cli.pull(self.image, stream=True): + for line in self.cli.pull(self.image, stream=True, decode=True): output = json.loads(line.decode('utf-8').strip()) if 'status' in output: self.log.info("%s", output['status']) diff --git a/tests/providers/docker/operators/test_docker.py b/tests/providers/docker/operators/test_docker.py index 89ecad372bbfaf..068eaefacf189f 100644 --- a/tests/providers/docker/operators/test_docker.py +++ b/tests/providers/docker/operators/test_docker.py @@ -85,7 +85,8 @@ def test_execute(self, client_class_mock, tempdir_mock): client_mock.images.assert_called_once_with(name='ubuntu:latest') client_mock.attach.assert_called_once_with(container='some_id', stdout=True, stderr=True, stream=True) - client_mock.pull.assert_called_once_with('ubuntu:latest', stream=True) + client_mock.pull.assert_called_once_with('ubuntu:latest', stream=True, + decode=True) client_mock.wait.assert_called_once_with('some_id') @mock.patch('airflow.providers.docker.operators.docker.tls.TLSConfig')