2021-10-15 16:56:19 |
Evan Ward |
description |
When using SQL scripts if the script has a "%" in it then it will fail to execute with the error "TypeError: dict is not a sequence". This seems to be due to sqlalchemy passing through Python % string formatting before executing it. The correct solution appears to be to escape any characters that offend sqlalchemy using `sqlalchemy.text`. For example the following statement runs in `psql` but fails when run with `migrate`.
```sql
do
$$
begin
execute format('select text(''%I'')', current_database());
end
$$;
```
Perhaps the right place to make the change is in migrate/versioning/script/sql.py before the statement is passed to sqlalchemy.
Workaround: Double the "%" as this escapes the character for Python's formatting. |
When using SQL scripts if the script has a "%" in it then it will fail to execute with the error "TypeError: dict is not a sequence". This seems to be due to sqlalchemy passing through Python % string formatting before executing it. The correct solution appears to be to escape any characters that offend sqlalchemy using `sqlalchemy.text`. For example the following statement runs in `psql` but fails when run with `migrate`.
do
$$
begin
execute format('select text(''%I'')', current_database());
end
$$;
Perhaps the right place to make the change is in migrate/versioning/script/sql.py before the statement is passed to sqlalchemy.
Workaround: Double the "%" as this escapes the character for Python's formatting. |
|
2021-10-15 16:58:01 |
Evan Ward |
description |
When using SQL scripts if the script has a "%" in it then it will fail to execute with the error "TypeError: dict is not a sequence". This seems to be due to sqlalchemy passing through Python % string formatting before executing it. The correct solution appears to be to escape any characters that offend sqlalchemy using `sqlalchemy.text`. For example the following statement runs in `psql` but fails when run with `migrate`.
do
$$
begin
execute format('select text(''%I'')', current_database());
end
$$;
Perhaps the right place to make the change is in migrate/versioning/script/sql.py before the statement is passed to sqlalchemy.
Workaround: Double the "%" as this escapes the character for Python's formatting. |
When using SQL scripts if the script has a "%" in it then it will fail to execute with the error "TypeError: dict is not a sequence". This seems to be due to sqlalchemy passing through Python % string formatting before executing it. The correct solution appears to be to escape any characters that offend sqlalchemy using `sqlalchemy.text`. For example the following statement runs in `psql` but fails when run with `migrate`.
do
$$
begin
execute format('select text(''%I'')', current_database());
end
$$;
Perhaps the right place to make the change is in migrate/versioning/script/sql.py before the statement is passed to sqlalchemy.
Workaround: Double the "%" as this escapes the character for Python's formatting.
Tested with Version: 0.13.0-0ubuntu1 from
http://us.archive.ubuntu.com/ubuntu hirsute/main amd64 Packages |
|