Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fixed _clean_sql #543

Merged
merged 1 commit into from
Jan 31, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
# 2024-01-31 (5.23.4)

* Bugfix in _is_valid_sql

# 2024-01-25 (5.23.3)

* Fix in _is_valid_sql to fix materialized view problem.
Expand Down
2 changes: 1 addition & 1 deletion setup.cfg
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[metadata]
name = amsterdam-schema-tools
version = 5.23.3
version = 5.23.4
url = https://github.com/amsterdam/schema-tools
license = Mozilla Public 2.0
author = Team Data Diensten, van het Dataplatform onder de Directie Digitale Voorzieningen (Gemeente Amsterdam)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ def _is_valid_sql(view_sql: str, view_name: str, write_role_name: str) -> bool:
sid = transaction.savepoint()
with connection.cursor() as cursor:
cursor.execute('SET statement_timeout = 5000;')
cursor.execute(view_sql)
cursor.execute(sql.SQL(view_sql))
transaction.savepoint_rollback(sid)
except Exception as e: # noqa: F841
return False
Expand Down Expand Up @@ -75,11 +75,7 @@ def _check_required_permissions_exist(
def _clean_sql(sql) -> str:
"""Clean the SQL to make it easier to parse."""

sql = sql.replace("\n", " ").lower().strip()

if sql[-1] != ";":
sql += ";"

sql = sql.replace("\n", " ").strip()
return sql


Expand Down Expand Up @@ -203,7 +199,7 @@ def create_views(
)

# Create the view
cursor.execute(view_sql)
cursor.execute(sql.SQL(view_sql))

# Reset the role to the default role
cursor.execute("RESET ROLE")
Expand Down
Loading