Skip to content

Commit

Permalink
[AIRFLOW-4363] Fix JSON encoding error (#7628)
Browse files Browse the repository at this point in the history
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 <[email protected]>
  • Loading branch information
retornam authored Mar 25, 2020
1 parent 4c067de commit 733d3d3
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 2 deletions.
2 changes: 1 addition & 1 deletion airflow/providers/docker/operators/docker.py
Original file line number Diff line number Diff line change
Expand Up @@ -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'])
Expand Down
3 changes: 2 additions & 1 deletion tests/providers/docker/operators/test_docker.py
Original file line number Diff line number Diff line change
Expand Up @@ -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')
Expand Down

0 comments on commit 733d3d3

Please sign in to comment.