From b5c783f853b9a154b1995e5e776ca9a5e67d0cfd Mon Sep 17 00:00:00 2001 From: Barry Daniels <101455655+barrydaniels-nl@users.noreply.github.com> Date: Thu, 25 Jan 2024 15:56:50 +0100 Subject: [PATCH] fixed problem with _is_valid_sql (#542) * fixed problem with _is_valid_sql * sloppy.. --------- Co-authored-by: Barry Daniels --- CHANGES.md | 4 ++++ setup.cfg | 2 +- .../django/management/commands/create_views.py | 12 +----------- 3 files changed, 6 insertions(+), 12 deletions(-) diff --git a/CHANGES.md b/CHANGES.md index f899fe2c..9e9e84a7 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -1,3 +1,7 @@ +# 2024-01-25 (5.23.3) + +* Fix in _is_valid_sql to fix materialized view problem. + # 2024-01-23 (5.23.2) * Fix to the _get_scopes to return the correct scopes for both dataset, table diff --git a/setup.cfg b/setup.cfg index 19fd5719..8bdf9edc 100644 --- a/setup.cfg +++ b/setup.cfg @@ -1,6 +1,6 @@ [metadata] name = amsterdam-schema-tools -version = 5.23.2 +version = 5.23.3 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) diff --git a/src/schematools/contrib/django/management/commands/create_views.py b/src/schematools/contrib/django/management/commands/create_views.py index 9fd4ae43..236d4462 100644 --- a/src/schematools/contrib/django/management/commands/create_views.py +++ b/src/schematools/contrib/django/management/commands/create_views.py @@ -24,16 +24,7 @@ def _is_valid_sql(view_sql: str, view_name: str, write_role_name: str) -> bool: with transaction.atomic(): sid = transaction.savepoint() with connection.cursor() as cursor: - - # Check if write role exists and create if it does not - _create_role_if_not_exists(cursor, write_role_name) - - cursor.execute( - sql.SQL("SET ROLE {write_role_name}").format( - write_role_name=sql.Identifier(write_role_name) - ) - ) - + cursor.execute('SET statement_timeout = 5000;') cursor.execute(view_sql) transaction.savepoint_rollback(sid) except Exception as e: # noqa: F841 @@ -44,7 +35,6 @@ def _is_valid_sql(view_sql: str, view_name: str, write_role_name: str) -> bool: def _get_scopes(datasetname: str, tablename: str) -> frozenset[str]: from functools import reduce from operator import __or__ - dataset = DATASETS.get(name=to_snake_case(datasetname)).schema if tablename in [table.id for table in dataset.tables]: table = dataset.get_table_by_id(tablename)