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 2021/10/27 19:13:01 UTC

[GitHub] [airflow] dstandish commented on issue #19096: Sets in parameters cause "TypeError: Object of type set is not JSON serializable"

dstandish commented on issue #19096:
URL: https://github.com/apache/airflow/issues/19096#issuecomment-953232043


   Taking a look at this.  But first wanted to establish a workaround.  And this seems to work:
   
   ```python
   from datetime import datetime
   from typing import Any
   
   from airflow.models import DAG, BaseOperator
   
   
   dag = DAG("paramtest",
             start_date=datetime(2021, 1, 1),
             schedule_interval="@daily", catchup=False, user_defined_macros={'set': lambda x: set(x)})
   
   
   @dag.task(params={"a": [1, 2, 3], "b": [3, 4, 5]})
   def intersect(intersection):
       print(intersection)
   
   
   intersect("{{ set(params.a).intersection(params.b).pop() }}")
   ```
   
   Notice that you need to add `set` as a macro, because builtins are not available in jinja.  But this allows you to use those same set  operations in a template. 


-- 
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.

To unsubscribe, e-mail: commits-unsubscribe@airflow.apache.org

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