[
https://issues.apache.org/jira/browse/AIRFLOW-1391?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=16412855#comment-16412855
]
Jeffrey Payne commented on AIRFLOW-1391:
----------------------------------------
It looks like {{json_client.py}} just isn't using the existing
{{AirflowJsonEncoder }}class. Is the server side already handling the
{{exec_date}} correctly?
> airflow trigger_dag cannot serialize exec_date when using the json client
> -------------------------------------------------------------------------
>
> Key: AIRFLOW-1391
> URL: https://issues.apache.org/jira/browse/AIRFLOW-1391
> Project: Apache Airflow
> Issue Type: Bug
> Components: api
> Affects Versions: 1.8.0
> Reporter: Ricardo Garcia Silva
> Priority: Major
> Labels: easyfix, newbie
>
> The {{airflow trigger_dag}} command cannot serialize a {{datetime.datetime}}
> when the cli is configured to use the {{json_client}}.
> The command:
> {code}
> airflow trigger_dag --run_id test1 --exec_date 2017-01-01
> example_bash_operator
> {code}
> Throws the error:
> {code}
> Traceback (most recent call last):
> File "/home/geo2/.venvs/cglops-dissemination/bin/airflow", line 28, in
> <module>
> args.func(args)
> File
> "/home/geo2/.venvs/cglops-dissemination/local/lib/python2.7/site-packages/airflow/bin/cli.py",
> line 180, in trigger_dag
> execution_date=args.exec_date)
> File
> "/home/geo2/.venvs/cglops-dissemination/local/lib/python2.7/site-packages/airflow/api/client/json_client.py",
> line 32, in trigger_dag
> "execution_date": execution_date,
> File
> "/home/geo2/.venvs/cglops-dissemination/local/lib/python2.7/site-packages/requests/api.py",
> line 112, in post
> return request('post', url, data=data, json=json, **kwargs)
> File
> "/home/geo2/.venvs/cglops-dissemination/local/lib/python2.7/site-packages/requests/api.py",
> line 58, in request
> return session.request(method=method, url=url, **kwargs)
> File
> "/home/geo2/.venvs/cglops-dissemination/local/lib/python2.7/site-packages/requests/sessions.py",
> line 488, in request
> prep = self.prepare_request(req)
> File
> "/home/geo2/.venvs/cglops-dissemination/local/lib/python2.7/site-packages/requests/sessions.py",
> line 431, in prepare_request
> hooks=merge_hooks(request.hooks, self.hooks),
> File
> "/home/geo2/.venvs/cglops-dissemination/local/lib/python2.7/site-packages/requests/models.py",
> line 308, in prepare
> self.prepare_body(data, files, json)
> File
> "/home/geo2/.venvs/cglops-dissemination/local/lib/python2.7/site-packages/requests/models.py",
> line 458, in prepare_body
> body = complexjson.dumps(json)
> File "/usr/lib/python2.7/json/__init__.py", line 243, in dumps
> return _default_encoder.encode(obj)
> File "/usr/lib/python2.7/json/encoder.py", line 207, in encode
> chunks = self.iterencode(o, _one_shot=True)
> File "/usr/lib/python2.7/json/encoder.py", line 270, in iterencode
> return _iterencode(o, 0)
> File "/usr/lib/python2.7/json/encoder.py", line 184, in default
> raise TypeError(repr(o) + " is not JSON serializable")
> TypeError: datetime.datetime(2017, 1, 1, 0, 0) is not JSON serializable
> {code}
> The same command works fine if airflow is configured to use the
> {{local_client}} instead.
> \\
> A fix for this would need to encode the {{datetime}} as a string in the
> client then being able to deserialize back to a datetime in the server.
--
This message was sent by Atlassian JIRA
(v7.6.3#76005)