Skip to content

Commit 0923e12

Browse files
Fix MWAA client's set_variable (#1524)
* Fix MWAA client's set_variable We need to escape quotes and escape sequences within the value of this function so Airflow can recognize the string Additionally, when we try to quote (and escape) with single quotes, Airflow returns a 500 error. We guess this is because Airflow is using escaped single quotes as part of its internal functioning
1 parent 1120551 commit 0923e12

2 files changed

Lines changed: 3 additions & 2 deletions

File tree

sqlmesh/schedulers/airflow/mwaa_client.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,8 @@ def set_variable(self, key: str, value: str) -> t.Tuple[str, str]:
3131
Returns:
3232
A tuple of stdout and stderr from the MWAA CLI.
3333
"""
34-
return self._post(f"variables set {key} '{value}'")
34+
value = value.replace("\\", "\\\\").replace('"', '\\"')
35+
return self._post(f'variables set {key} "{value}"')
3536

3637
def get_first_dag_run_id(self, dag_id: str) -> t.Optional[str]:
3738
dag_runs = self._list_dag_runs(dag_id)

tests/schedulers/airflow/test_mwaa_client.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ def test_set_variable(mocker: MockerFixture):
2222

2323
set_variable_mock.assert_called_once_with(
2424
"https://test_airflow_host/aws_mwaa/cli",
25-
data="variables set test_key 'test_value'",
25+
data='variables set test_key "test_value"',
2626
)
2727

2828

0 commit comments

Comments
 (0)