write airflow dag with conditional branch
- User
write airflow dag with conditional branch
- Assistant
Here is an example of an Airflow DAG with a conditional branch:
python - User
what is the error? ERROR - Task failed with exception Traceback (most recent call last): File "/home/airflow/.local/lib/python3.7/site-packages/airflow/utils/session.py", line 72, in wrapper return func(*args, **kwargs) File "/home/airflow/.local/lib/python3.7/site-packages/airflow/models/taskinstance.py", line 2305, in xcom_push session=session, File "/home/airflow/.local/lib/python3.7/site-packages/airflow/utils/session.py", line 72, in wrapper return func(*args, **kwargs) File "/home/airflow/.local/lib/python3.7/site-packages/airflow/models/xcom.py", line 240, in set map_index=map_index, File "/home/airflow/.local/lib/python3.7/site-packages/airflow/models/xcom.py", line 627, in serialize_value return json.dumps(value, cls=XComEncoder).encode("UTF-8") File "/usr/local/lib/python3.7/json/init.py", line 238, in dumps **kw).encode(obj) File "/home/airflow/.local/lib/python3.7/site-packages/airflow/utils/json.py", line 176, in encode return super().encode(o) File "/usr/local/lib/python3.7/json/encoder.py", line 199, in encode chunks = self.iterencode(o, _one_shot=True) File "/usr/local/lib/python3.7/json/encoder.py", line 257, in iterencode return _iterencode(o, 0) File "/home/airflow/.local/lib/python3.7/site-packages/airflow/utils/json.py", line 153, in default CLASSNAME: o. + "." + o.., AttributeError: 'numpy.int64' object has no attribute ''
- Assistant
The error you are encountering is related to serializing the value pushed to XCom. The error message suggests that you are trying to serialize a 'numpy.int64' object which does not have the 'module' attribute required by the serializer.
To fix this issue, you can convert the value to a regular Python int before pushing it to XCom. Here's an updated version of the code to handle this conversion:
python