You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@airflow.apache.org by GitBox <gi...@apache.org> on 2020/12/28 15:14:43 UTC

[GitHub] [airflow] darwinyip opened a new issue #13342: XCOM UI: TypeError: Object of type 'DatetimeWithNanoseconds' is not JSON serializable

darwinyip opened a new issue #13342:
URL: https://github.com/apache/airflow/issues/13342


   **Apache Airflow version**: 1.10.10
   
   **What happened**:
   After returning a `DatetimeWithNanoseconds` as Xcom, the UI page for `XComs` errors out with the following error:
   
   ```
   Traceback (most recent call last):
     File "/usr/local/lib/python3.6/site-packages/flask/app.py", line 2447, in wsgi_app
       response = self.full_dispatch_request()
     File "/usr/local/lib/python3.6/site-packages/flask/app.py", line 1952, in full_dispatch_request
       rv = self.handle_user_exception(e)
     File "/usr/local/lib/python3.6/site-packages/flask/app.py", line 1821, in handle_user_exception
       reraise(exc_type, exc_value, tb)
     File "/usr/local/lib/python3.6/site-packages/flask/_compat.py", line 39, in reraise
       raise value
     File "/usr/local/lib/python3.6/site-packages/flask/app.py", line 1950, in full_dispatch_request
       rv = self.dispatch_request()
     File "/usr/local/lib/python3.6/site-packages/flask/app.py", line 1936, in dispatch_request
       return self.view_functions[rule.endpoint](**req.view_args)
     File "/usr/local/lib/python3.6/site-packages/flask_admin/base.py", line 69, in inner
       return self._run_view(f, *args, **kwargs)
     File "/usr/local/lib/python3.6/site-packages/flask_admin/base.py", line 368, in _run_view
       return fn(self, *args, **kwargs)
     File "/usr/local/lib/python3.6/site-packages/flask_admin/model/base.py", line 2069, in index_view
       extra_args=view_args.extra_args,
     File "/usr/local/lib/python3.6/site-packages/airflow/www/views.py", line 389, in render
       return super(AirflowViewMixin, self).render(template, **kwargs)
     File "/usr/local/lib/python3.6/site-packages/flask_admin/base.py", line 308, in render
       return render_template(template, **kwargs)
     File "/usr/local/lib/python3.6/site-packages/flask/templating.py", line 140, in render_template
       ctx.app,
     File "/usr/local/lib/python3.6/site-packages/flask/templating.py", line 120, in _render
       rv = template.render(context)
     File "/usr/local/lib/python3.6/site-packages/jinja2/asyncsupport.py", line 76, in render
       return original_render(self, *args, **kwargs)
     File "/usr/local/lib/python3.6/site-packages/jinja2/environment.py", line 1008, in render
       return self.environment.handle_exception(exc_info, True)
     File "/usr/local/lib/python3.6/site-packages/jinja2/environment.py", line 780, in handle_exception
       reraise(exc_type, exc_value, tb)
     File "/usr/local/lib/python3.6/site-packages/jinja2/_compat.py", line 37, in reraise
       raise value.with_traceback(tb)
     File "/usr/local/lib/python3.6/site-packages/airflow/www/templates/airflow/model_list.html", line 19, in top-level template code
       {% extends 'admin/model/list.html' %}
     File "/usr/local/lib/python3.6/site-packages/flask_admin/templates/bootstrap3/admin/model/list.html", line 6, in top-level template code
       {% import 'admin/model/row_actions.html' as row_actions with context %}
     File "/usr/local/lib/python3.6/site-packages/airflow/www/templates/admin/master.html", line 20, in top-level template code
       {% extends 'admin/base.html' %}
     File "/usr/local/lib/python3.6/site-packages/flask_admin/templates/bootstrap3/admin/base.html", line 38, in top-level template code
       {% block page_body %}
     File "/usr/local/lib/python3.6/site-packages/airflow/www/templates/admin/master.html", line 191, in block "page_body"
       {% block body %}
     File "/usr/local/lib/python3.6/site-packages/flask_admin/templates/bootstrap3/admin/model/list.html", line 68, in block "body"
       {% block model_list_table %}
     File "/usr/local/lib/python3.6/site-packages/flask_admin/templates/bootstrap3/admin/model/list.html", line 116, in block "model_list_table"
       {% block list_row scoped %}
     File "/usr/local/lib/python3.6/site-packages/flask_admin/templates/bootstrap3/admin/model/list.html", line 144, in block "list_row"
       {{ get_value(row, c) }}
     File "/usr/local/lib/python3.6/site-packages/flask_admin/model/base.py", line 1871, in get_list_value
       self.column_type_formatters,
     File "/usr/local/lib/python3.6/site-packages/flask_admin/model/base.py", line 1850, in _get_list_value
       value = type_fmt(self, value)
     File "/usr/local/lib/python3.6/site-packages/flask_admin/model/typefmt.py", line 71, in dict_formatter
       return json.dumps(value, ensure_ascii=False)
     File "/usr/local/lib/python3.6/json/__init__.py", line 238, in dumps
       **kw).encode(obj)
     File "/usr/local/lib/python3.6/json/encoder.py", line 199, in encode
       chunks = self.iterencode(o, _one_shot=True)
     File "/usr/local/lib/python3.6/json/encoder.py", line 257, in iterencode
       return _iterencode(o, 0)
     File "/usr/local/lib/python3.6/json/encoder.py", line 180, in default
       o.__class__.__name__)
   TypeError: Object of type 'DatetimeWithNanoseconds' is not JSON serializable
   ```
   
   **How to reproduce it**:
   This happens when working with GCP API and returning part of their response.


----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [airflow] turbaszek commented on issue #13342: XCOM UI: TypeError: Object of type 'DatetimeWithNanoseconds' is not JSON serializable

Posted by GitBox <gi...@apache.org>.
turbaszek commented on issue #13342:
URL: https://github.com/apache/airflow/issues/13342#issuecomment-751805507


   Additionally, doing:
   ```
   def return_datetime_with_nanoseconds(**kwargs):
       return DatetimeWithNanoseconds(2020, 6, 22, 17, 1, 30, 12345)
   ```
   also raises exactly the same error. The only possibility is that the XCom was used using pickle, and webserver is trying to read it using JSON - but that would be suggesting some configuration issues. 


----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [airflow] turbaszek commented on issue #13342: XCOM UI: TypeError: Object of type 'DatetimeWithNanoseconds' is not JSON serializable

Posted by GitBox <gi...@apache.org>.
turbaszek commented on issue #13342:
URL: https://github.com/apache/airflow/issues/13342#issuecomment-751804254


   > @turbaszek I think it is an airflow issue because it renders fine when you go "Task Instance Details -> XCom"
   
   Cannot replicate on master, where the DAG of yours fails:
   ```
   *** Reading local file: /root/airflow/logs/test_proto/return-ns/2020-12-28T17:43:39.819616+00:00/1.log
   [2020-12-28 17:43:41,745] {taskinstance.py:826} INFO - Dependencies all met for <TaskInstance: test_proto.return-ns 2020-12-28T17:43:39.819616+00:00 [queued]>
   [2020-12-28 17:43:41,746] {taskinstance.py:826} INFO - Dependencies all met for <TaskInstance: test_proto.return-ns 2020-12-28T17:43:39.819616+00:00 [queued]>
   [2020-12-28 17:43:41,748] {taskinstance.py:1017} INFO - 
   --------------------------------------------------------------------------------
   [2020-12-28 17:43:41,750] {taskinstance.py:1018} INFO - Starting attempt 1 of 1
   [2020-12-28 17:43:41,752] {taskinstance.py:1019} INFO - 
   --------------------------------------------------------------------------------
   [2020-12-28 17:43:41,780] {taskinstance.py:1038} INFO - Executing <Task(PythonOperator): return-ns> on 2020-12-28T17:43:39.819616+00:00
   [2020-12-28 17:43:41,790] {standard_task_runner.py:51} INFO - Started process 2011 to run task
   [2020-12-28 17:43:41,839] {standard_task_runner.py:75} INFO - Running: ['airflow', 'tasks', 'run', 'test_proto', 'return-ns', '2020-12-28T17:43:39.819616+00:00', '--job-id', '4', '--pool', 'default_pool', '--raw', '--subdir', '/files/dags/xcom.py', '--cfg-path', '/tmp/tmpjw1ehkwn']
   [2020-12-28 17:43:41,851] {standard_task_runner.py:76} INFO - Job 4: Subtask return-ns
   [2020-12-28 17:43:41,982] {logging_mixin.py:103} INFO - Running <TaskInstance: test_proto.return-ns 2020-12-28T17:43:39.819616+00:00 [running]> on host 17cf180a4ef0
   [2020-12-28 17:43:42,085] {taskinstance.py:1232} INFO - Exporting the following env vars:
   AIRFLOW_CTX_DAG_OWNER=airflow
   AIRFLOW_CTX_DAG_ID=test_proto
   AIRFLOW_CTX_TASK_ID=return-ns
   AIRFLOW_CTX_EXECUTION_DATE=2020-12-28T17:43:39.819616+00:00
   AIRFLOW_CTX_DAG_RUN_ID=manual__2020-12-28T17:43:39.819616+00:00
   [2020-12-28 17:43:42,091] {python.py:118} INFO - Done. Returned value was: {'time': DatetimeWithNanoseconds(2020, 6, 22, 17, 1, 30, 12345)}
   [2020-12-28 17:43:42,093] {xcom.py:238} ERROR - Could not serialize the XCom value into JSON. If you are using pickles instead of JSON for XCom, then you need to enable pickle support for XCom in your airflow config.
   [2020-12-28 17:43:42,095] {taskinstance.py:1396} ERROR - Object of type 'DatetimeWithNanoseconds' is not JSON serializable
   Traceback (most recent call last):
     File "/opt/airflow/airflow/models/taskinstance.py", line 1086, in _run_raw_task
       self._prepare_and_execute_task_with_callbacks(context, task)
     File "/opt/airflow/airflow/models/taskinstance.py", line 1260, in _prepare_and_execute_task_with_callbacks
       result = self._execute_task(context, task_copy)
     File "/opt/airflow/airflow/models/taskinstance.py", line 1303, in _execute_task
       self.xcom_push(key=XCOM_RETURN_KEY, value=result)
     File "/opt/airflow/airflow/utils/session.py", line 65, in wrapper
       return func(*args, session=session, **kwargs)
     File "/opt/airflow/airflow/models/taskinstance.py", line 1833, in xcom_push
       session=session,
     File "/opt/airflow/airflow/utils/session.py", line 62, in wrapper
       return func(*args, **kwargs)
     File "/opt/airflow/airflow/models/xcom.py", line 88, in set
       value = XCom.serialize_value(value)
     File "/opt/airflow/airflow/models/xcom.py", line 235, in serialize_value
       return json.dumps(value).encode('UTF-8')
     File "/usr/local/lib/python3.6/json/__init__.py", line 231, in dumps
       return _default_encoder.encode(obj)
     File "/usr/local/lib/python3.6/json/encoder.py", line 199, in encode
       chunks = self.iterencode(o, _one_shot=True)
     File "/usr/local/lib/python3.6/json/encoder.py", line 257, in iterencode
       return _iterencode(o, 0)
     File "/usr/local/lib/python3.6/json/encoder.py", line 180, in default
       o.__class__.__name__)
   TypeError: Object of type 'DatetimeWithNanoseconds' is not JSON serializable
   [2020-12-28 17:43:42,117] {taskinstance.py:1440} INFO - Marking task as FAILED. dag_id=test_proto, task_id=return-ns, execution_date=20201228T174339, start_date=20201228T174341, end_date=20201228T174342
   [2020-12-28 17:43:42,182] {local_task_job.py:118} INFO - Task exited with return code 1
   ```


----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [airflow] turbaszek commented on issue #13342: XCOM UI: TypeError: Object of type 'DatetimeWithNanoseconds' is not JSON serializable

Posted by GitBox <gi...@apache.org>.
turbaszek commented on issue #13342:
URL: https://github.com/apache/airflow/issues/13342#issuecomment-751757906


   > This happens when working with GCP API and returning part of their response.
   
   What part of GCP API? Do you use some Google operator or a custom one?


----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [airflow] darwinyip commented on issue #13342: XCOM UI: TypeError: Object of type 'DatetimeWithNanoseconds' is not JSON serializable

Posted by GitBox <gi...@apache.org>.
darwinyip commented on issue #13342:
URL: https://github.com/apache/airflow/issues/13342#issuecomment-751791341


   @turbaszek I was able to reproduce it
   
   ```
   from datetime import datetime
   
   from airflow import DAG
   from airflow.operators.python_operator import PythonOperator
   from proto.datetime_helpers import DatetimeWithNanoseconds
   
   default_args = {
       "owner": "airflow",
       "start_date": datetime(2020, 12, 28),
       'schedule_interval': None,
   }
   
   
   def return_datetime_with_nanoseconds(**kwargs):
       return {
           "time": DatetimeWithNanoseconds(2020, 6, 22, 17, 1, 30, 12345)
       }
   
   
   dag = DAG(
       'test_proto',
       default_args=default_args
   )
   
   return_ns = PythonOperator(
       task_id='return-ns',
       python_callable=return_datetime_with_nanoseconds,
       dag=dag
   )
   ```
   
   Initially I was just returning `DatetimeWithNanoseconds(2020, 6, 22, 17, 1, 30, 12345)` but after putting in a dictionary, I triggered the error.


----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [airflow] turbaszek commented on issue #13342: XCOM UI: TypeError: Object of type 'DatetimeWithNanoseconds' is not JSON serializable

Posted by GitBox <gi...@apache.org>.
turbaszek commented on issue #13342:
URL: https://github.com/apache/airflow/issues/13342#issuecomment-751784519


   > Apologies for the bad description. I am trying to reproduce it unsuccessfully and also don't know which Xcom entry is causing it either.
   
   No worry, let us know once you have more information. In general this should never happen - the error should be raised when executing an operator (when pushing the value to XCom). Do you use possibly pickle for XCom?


----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [airflow] turbaszek edited a comment on issue #13342: XCOM UI: TypeError: Object of type 'DatetimeWithNanoseconds' is not JSON serializable

Posted by GitBox <gi...@apache.org>.
turbaszek edited a comment on issue #13342:
URL: https://github.com/apache/airflow/issues/13342#issuecomment-751797761


   Well, this is expected, json don't know how to serialise this (or any other non-generic type).
   
   Have you tried this?
   ```py
   DatetimeWithNanoseconds(2020, 6, 22, 17, 1, 30, 12345).rfc3339()
   ```
   This should return the date as string, but parsing it back to object should be easy as there is already `from_rfc3339` method in `proto` package. 
   
   
   Closing as not an Airflow issue.


----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [airflow] turbaszek commented on issue #13342: XCOM UI: TypeError: Object of type 'DatetimeWithNanoseconds' is not JSON serializable

Posted by GitBox <gi...@apache.org>.
turbaszek commented on issue #13342:
URL: https://github.com/apache/airflow/issues/13342#issuecomment-751797761


   Well, this is expected, json don't know how to serialise this (or any other non-generic one).
   
   Have you tried this?
   ```py
   DatetimeWithNanoseconds(2020, 6, 22, 17, 1, 30, 12345).rfc3339()
   ```
   This should return the date as string, but parsing it back to object should be easy as there is already `from_rfc3339` method in `proto` package. 
   


----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [airflow] turbaszek closed issue #13342: XCOM UI: TypeError: Object of type 'DatetimeWithNanoseconds' is not JSON serializable

Posted by GitBox <gi...@apache.org>.
turbaszek closed issue #13342:
URL: https://github.com/apache/airflow/issues/13342


   


----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [airflow] darwinyip commented on issue #13342: XCOM UI: TypeError: Object of type 'DatetimeWithNanoseconds' is not JSON serializable

Posted by GitBox <gi...@apache.org>.
darwinyip commented on issue #13342:
URL: https://github.com/apache/airflow/issues/13342#issuecomment-751767970


   Apologies for the bad description. I am trying to reproduce it unsuccessfully and also don't know which Xcom entry is causing it either.


----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [airflow] darwinyip commented on issue #13342: XCOM UI: TypeError: Object of type 'DatetimeWithNanoseconds' is not JSON serializable

Posted by GitBox <gi...@apache.org>.
darwinyip commented on issue #13342:
URL: https://github.com/apache/airflow/issues/13342#issuecomment-751801040


   @turbaszek I think it is an airflow issue because it renders fine when you go "Task Instance Details -> XCom"


----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [airflow] turbaszek edited a comment on issue #13342: XCOM UI: TypeError: Object of type 'DatetimeWithNanoseconds' is not JSON serializable

Posted by GitBox <gi...@apache.org>.
turbaszek edited a comment on issue #13342:
URL: https://github.com/apache/airflow/issues/13342#issuecomment-751797761


   Well, this is expected, json don't know how to serialise this (or any other non-generic one).
   
   Have you tried this?
   ```py
   DatetimeWithNanoseconds(2020, 6, 22, 17, 1, 30, 12345).rfc3339()
   ```
   This should return the date as string, but parsing it back to object should be easy as there is already `from_rfc3339` method in `proto` package. 
   
   
   Closing as not an Airflow issue.


----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [airflow] darwinyip commented on issue #13342: XCOM UI: TypeError: Object of type 'DatetimeWithNanoseconds' is not JSON serializable

Posted by GitBox <gi...@apache.org>.
darwinyip commented on issue #13342:
URL: https://github.com/apache/airflow/issues/13342#issuecomment-751809931


   Checking through the configs, I do have `enable_xcom_pickling = True`


----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org