kaxil edited a comment on issue #13414:
URL: https://github.com/apache/airflow/issues/13414#issuecomment-769248659


   We need to add the diff at the end in `TriggerDagRunOperator`, we don't want 
to allow arbitrary objects. To pass datetime you should convert it to str, you 
could do `datetime.datetime.now().isoformat()`:
   
   ```python
   In [2]: import datetime
   
   In [3]: datetime.datetime.now().isoformat()
   Out[3]: '2021-01-28T17:28:14.082547'
   ```
   
   ```diff
   diff --git a/airflow/operators/trigger_dagrun.py 
b/airflow/operators/trigger_dagrun.py
   index 63d336115..86078bbec 100644
   --- a/airflow/operators/trigger_dagrun.py
   +++ b/airflow/operators/trigger_dagrun.py
   @@ -23,6 +23,7 @@ from typing import Dict, List, Optional, Union
    from airflow.api.common.experimental.trigger_dag import trigger_dag
    from airflow.exceptions import AirflowException, DagNotFound, 
DagRunAlreadyExists
    from airflow.models import BaseOperator, BaseOperatorLink, DagBag, 
DagModel, DagRun
   +from airflow.settings import json
    from airflow.utils import timezone
    from airflow.utils.decorators import apply_defaults
    from airflow.utils.helpers import build_airflow_url_with_query
   @@ -108,6 +109,11 @@ class TriggerDagRunOperator(BaseOperator):
   
            self.execution_date: Optional[datetime.datetime] = execution_date  
# type: ignore
   
   +        try:
   +            json.dumps(self.conf)
   +        except TypeError:
   +            raise AirflowException("conf parameter should be JSON 
Serializable")
   +
        def execute(self, context: Dict):
            if isinstance(self.execution_date, datetime.datetime):
                execution_date = self.execution_date
   ```
   
   This diff will enforce that value passed to `conf` is JSON Serializable


----------------------------------------------------------------
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:
[email protected]


Reply via email to