If a task_instance export has a json object on next_kwargs field, the mwaa_export.py writes the object as a string with single quotes (i.e. "{'__var': {}, '__type': 'dict'}")
The mwaa_import.py COPY command, for json objects is expecting the field in the following format: {"__var": {}, "__type": "dict"}
as result, the import fails with the following error:
[2024-05-17T11:48:18.260+0000] {{taskinstance.py:1937}} ERROR - Task failed with exception
Traceback (most recent call last):
File "/usr/local/airflow/.local/lib/python3.11/site-packages/airflow/operators/python.py", line 192, in execute
return_value = self.execute_callable()
^^^^^^^^^^^^^^^^^^^^^^^
File "/usr/local/airflow/.local/lib/python3.11/site-packages/airflow/operators/python.py", line 209, in execute_callable
return self.python_callable(*self.op_args, **self.op_kwargs)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/usr/local/airflow/dags/mwaa_import.py", line 192, in load_data
cursor.copy_expert(query, f)
psycopg2.errors.InvalidTextRepresentation: invalid input syntax for type json
DETAIL: Token "'" is invalid.
CONTEXT: JSON data, line 1: {'...
COPY task_instance, line 4811, column next_kwargs: "{'__var': {}, '__type': 'dict'}"