From 84cbbda22a31a28468f562557bdbe2f4805b7f67 Mon Sep 17 00:00:00 2001 From: Kanoma <87711035+kamilamarcinekpgs@users.noreply.github.com> Date: Mon, 29 May 2023 14:07:53 +0200 Subject: [PATCH 1/2] Update upload_model_executions.sql Replace single quotes and other special characters in model.message. --- macros/upload_model_executions.sql | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/macros/upload_model_executions.sql b/macros/upload_model_executions.sql index 2cc7b861..476c7ba7 100644 --- a/macros/upload_model_executions.sql +++ b/macros/upload_model_executions.sql @@ -72,7 +72,7 @@ '{{ model.node.schema }}', {# schema #} '{{ model.node.name }}', {# name #} '{{ model.node.alias }}', {# alias #} - '{{ model.message }}', {# message #} + '{{ model.message | replace("\\", "\\\\") | replace("'", "\\'") | replace('"', '\\"') }}', {# message #} '{{ tojson(model.adapter_response) | replace("\\", "\\\\") | replace("'", "\\'") | replace('"', '\\"') }}' {# adapter_response #} ) {%- if not loop.last %},{%- endif %} @@ -130,7 +130,7 @@ '{{ model.node.schema }}', {# schema #} '{{ model.node.name }}', {# name #} '{{ model.node.alias }}', {# alias #} - '{{ model.message }}', {# message #} + '{{ model.message | replace("\\", "\\\\") | replace("'", "\\'") | replace('"', '\\"') }}', {# message #} parse_json('{{ tojson(model.adapter_response) | replace("\\", "\\\\") | replace("'", "\\'") | replace('"', '\\"') }}') {# adapter_response #} ) {%- if not loop.last %},{%- endif %} @@ -205,7 +205,7 @@ '{{ model.node.schema }}', {# schema #} '{{ model.node.name }}', {# name #} '{{ model.node.alias }}', {# alias #} - '{{ model.message }}', {# message #} + '{{ model.message | replace("\\", "\\\\") | replace("'", "\\'") | replace('"', '\\"') }}', {# message #} '{{ tojson(model.adapter_response) | replace("\\", "\\\\") | replace("'", "\\'") | replace('"', '\\"') }}' {# adapter_response #} ) {%- if not loop.last %},{%- endif %} From cf1409c7e86d9375d71355f79cd5c422caf3f4f2 Mon Sep 17 00:00:00 2001 From: Kamila Marcinek Date: Tue, 30 May 2023 13:07:26 +0200 Subject: [PATCH 2/2] Replacing special characters in the MESSAGE field in all _executions macros. --- macros/upload_seed_executions.sql | 6 +++--- macros/upload_snapshot_executions.sql | 6 +++--- macros/upload_test_executions.sql | 4 ++-- 3 files changed, 8 insertions(+), 8 deletions(-) diff --git a/macros/upload_seed_executions.sql b/macros/upload_seed_executions.sql index bbbf9acf..a3a9d521 100644 --- a/macros/upload_seed_executions.sql +++ b/macros/upload_seed_executions.sql @@ -71,7 +71,7 @@ '{{ model.node.schema }}', {# schema #} '{{ model.node.name }}', {# name #} '{{ model.node.alias }}', {# alias #} - '{{ model.message }}', {# message #} + '{{ model.message | replace("\\", "\\\\") | replace("'", "\\'") | replace('"', '\\"') }}', {# message #} '{{ tojson(model.adapter_response) | replace("\\", "\\\\") | replace("'", "\\'") | replace('"', '\\"') }}' {# adapter_response #} ) {%- if not loop.last %},{%- endif %} @@ -128,7 +128,7 @@ '{{ model.node.schema }}', {# schema #} '{{ model.node.name }}', {# name #} '{{ model.node.alias }}', {# alias #} - '{{ model.message }}', {# message #} + '{{ model.message | replace("\\", "\\\\") | replace("'", "\\'") | replace('"', '\\"') }}', {# message #} parse_json('{{ tojson(model.adapter_response) | replace("\\", "\\\\") | replace("'", "\\'") | replace('"', '\\"') }}') {# adapter_response #} ) {%- if not loop.last %},{%- endif %} @@ -203,7 +203,7 @@ '{{ model.node.schema }}', {# schema #} '{{ model.node.name }}', {# name #} '{{ model.node.alias }}', {# alias #} - '{{ model.message }}', {# message #} + '{{ model.message | replace("\\", "\\\\") | replace("'", "\\'") | replace('"', '\\"') }}', {# message #} '{{ tojson(model.adapter_response) | replace("\\", "\\\\") | replace("'", "\\'") | replace('"', '\\"') }}' {# adapter_response #} ) {%- if not loop.last %},{%- endif %} diff --git a/macros/upload_snapshot_executions.sql b/macros/upload_snapshot_executions.sql index 9b4fe913..e0bf6dac 100644 --- a/macros/upload_snapshot_executions.sql +++ b/macros/upload_snapshot_executions.sql @@ -71,7 +71,7 @@ '{{ model.node.schema }}', {# schema #} '{{ model.node.name }}', {# name #} '{{ model.node.alias }}', {# alias #} - '{{ model.message }}', {# message #} + '{{ model.message | replace("\\", "\\\\") | replace("'", "\\'") | replace('"', '\\"') }}', {# message #} '{{ tojson(model.adapter_response) | replace("\\", "\\\\") | replace("'", "\\'") | replace('"', '\\"') }}' {# adapter_response #} ) {%- if not loop.last %},{%- endif %} @@ -128,7 +128,7 @@ '{{ model.node.schema }}', {# schema #} '{{ model.node.name }}', {# name #} '{{ model.node.alias }}', {# alias #} - '{{ model.message }}', {# message #} + '{{ model.message | replace("\\", "\\\\") | replace("'", "\\'") | replace('"', '\\"') }}', {# message #} parse_json('{{ tojson(model.adapter_response) | replace("\\", "\\\\") | replace("'", "\\'") | replace('"', '\\"') }}') {# adapter_response #} ) {%- if not loop.last %},{%- endif %} @@ -203,7 +203,7 @@ '{{ model.node.schema }}', {# schema #} '{{ model.node.name }}', {# name #} '{{ model.node.alias }}', {# alias #} - '{{ model.message }}', {# message #} + '{{ model.message | replace("\\", "\\\\") | replace("'", "\\'") | replace('"', '\\"') }}', {# message #} '{{ tojson(model.adapter_response) | replace("\\", "\\\\") | replace("'", "\\'") | replace('"', '\\"') }}' {# adapter_response #} ) {%- if not loop.last %},{%- endif %} diff --git a/macros/upload_test_executions.sql b/macros/upload_test_executions.sql index 54d6c4a1..198fc95f 100644 --- a/macros/upload_test_executions.sql +++ b/macros/upload_test_executions.sql @@ -65,7 +65,7 @@ {{ test.execution_time }}, {# total_node_runtime #} null, {# rows_affected not available in Databricks #} {{ 'null' if test.failures is none else test.failures }}, {# failures #} - '{{ test.message }}', {# message #} + '{{ test.message | replace("\\", "\\\\") | replace("'", "\\'") | replace('"', '\\"') }}', {# message #} '{{ tojson(test.adapter_response) | replace("\\", "\\\\") | replace("'", "\\'") | replace('"', '\\"') }}' {# adapter_response #} ) {%- if not loop.last %},{%- endif %} @@ -119,7 +119,7 @@ {{ test.execution_time }}, {# total_node_runtime #} null, {# rows_affected not available in Databricks #} {{ 'null' if test.failures is none else test.failures }}, {# failures #} - '{{ test.message }}', {# message #} + '{{ test.message | replace("\\", "\\\\") | replace("'", "\\'") | replace('"', '\\"') }}', {# message #} parse_json('{{ tojson(test.adapter_response) | replace("\\", "\\\\") | replace("'", "\\'") | replace('"', '\\"') }}') {# adapter_response #} )