You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@airflow.apache.org by "Aizhamal Nurmamat kyzy (JIRA)" <ji...@apache.org> on 2019/05/18 02:29:01 UTC

[jira] [Updated] (AIRFLOW-565) DockerOperator doesn't work on Python3.4

     [ https://issues.apache.org/jira/browse/AIRFLOW-565?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

Aizhamal Nurmamat kyzy updated AIRFLOW-565:
-------------------------------------------
         Labels: docker  (was: )
    Component/s:     (was: docker)

Moving to `operators` component, and labeling with `docker` for component refactor.

> DockerOperator doesn't work on Python3.4
> ----------------------------------------
>
>                 Key: AIRFLOW-565
>                 URL: https://issues.apache.org/jira/browse/AIRFLOW-565
>             Project: Apache Airflow
>          Issue Type: Bug
>          Components: operators
>    Affects Versions: 1.7.1.3
>         Environment: Python 3.4.3
>            Reporter: Vitor Baptista
>            Assignee: Vitor Baptista
>            Priority: Major
>              Labels: docker
>
> On {{DockerOperator.execute()}} we have:
> {code}
> if self.force_pull or len(self.cli.images(name=image)) == 0:
>         logging.info('Pulling docker image ' + image)
>         for l in self.cli.pull(image, stream=True):
>             output = json.loads(l)
>             logging.info("{}".format(output['status']))
> {code}
> https://github.com/apache/incubator-airflow/blob/master/airflow/operators/docker_operator.py#L152-L156
> The {{self.cli.pull()}} method returns {{bytes}} in Python3.4, and {{json.loads()}} expects a string, so we end up with:
> {code}
> Traceback (most recent call last):
>   File "/home/vitor/Projetos/okfn/opentrials/airflow/env/lib/python3.4/site-packages/airflow/models.py", line 1245, in run
>     result = task_copy.execute(context=context)
>   File "/home/vitor/Projetos/okfn/opentrials/airflow/env/lib/python3.4/site-packages/airflow/operators/docker_operator.py", line 142, in execute
>     logging.info("{}".format(output['status']))
>   File "/usr/lib/python3.4/json/__init__.py", line 312, in loads
>     s.__class__.__name__))
> TypeError: the JSON object must be str, not 'bytes'
> {code}
> To avoid this, we could simply change it to {{output = json.loads(l.encode('utf-8'))}}. This hardcodes the string as UTF-8, which should be fine, considering the JSON spec requires the use of UTF-8, UTF-16 or UTF-32. As we're dealing with a Docker server, we can assume they'll be well behaved.
> I'm happy to submit a pull request for this if you agree with the solution.



--
This message was sent by Atlassian JIRA
(v7.6.3#76005)