From cb78e1e06ccaf85ee2d70412498c36976b5986e1 Mon Sep 17 00:00:00 2001 From: tnazarew Date: Mon, 16 Nov 2026 14:40:18 +0100 Subject: [PATCH] dbt: match data quality assertions in any order dbt runs tests on 4 threads, so the order of dataQualityAssertions.assertions in the test COMPLETE events changes from run to run, and the csv_to_postgres expectations fail at random (seen on customer_analytics: total_revenue and customer_id not_null swapped). Compare the assertions with unordered_list. That needed a fix in compare_events: unordered_list called the module's own any() (the jinja helper, which returns a string) instead of the builtin and compared lists with `is []`, so it never matched anything. No expectation used it until now. Co-Authored-By: Claude Opus 5.5 Signed-off-by: tnazarew --- .../csv_to_postgres/events/analytics/data_quality_event.json | 2 +- .../csv_to_postgres/events/customers/data_quality_event.json | 2 +- .../csv_to_postgres/events/orders/data_quality_event.json | 2 +- scripts/compare_events.py | 4 +++- 4 files changed, 6 insertions(+), 4 deletions(-) diff --git a/producer/dbt/scenarios/csv_to_postgres/events/analytics/data_quality_event.json b/producer/dbt/scenarios/csv_to_postgres/events/analytics/data_quality_event.json index 685d2861..c8fe1696 100644 --- a/producer/dbt/scenarios/csv_to_postgres/events/analytics/data_quality_event.json +++ b/producer/dbt/scenarios/csv_to_postgres/events/analytics/data_quality_event.json @@ -10,7 +10,7 @@ "namespace": "postgres://localhost:5432", "facets": { "dataQualityAssertions": { - "assertions": [ + "{{ unordered_list(result, 'assertions') }}": [ { "assertion": "not_null", "name": "not_null_customer_analytics_total_revenue", diff --git a/producer/dbt/scenarios/csv_to_postgres/events/customers/data_quality_event.json b/producer/dbt/scenarios/csv_to_postgres/events/customers/data_quality_event.json index 1a52b933..9500aaf4 100644 --- a/producer/dbt/scenarios/csv_to_postgres/events/customers/data_quality_event.json +++ b/producer/dbt/scenarios/csv_to_postgres/events/customers/data_quality_event.json @@ -10,7 +10,7 @@ "namespace": "postgres://localhost:5432", "facets": { "dataQualityAssertions": { - "assertions": [ + "{{ unordered_list(result, 'assertions') }}": [ { "assertion": "not_null", "name": "not_null_stg_customers_customer_id", diff --git a/producer/dbt/scenarios/csv_to_postgres/events/orders/data_quality_event.json b/producer/dbt/scenarios/csv_to_postgres/events/orders/data_quality_event.json index ba5ebe7d..56e6d643 100644 --- a/producer/dbt/scenarios/csv_to_postgres/events/orders/data_quality_event.json +++ b/producer/dbt/scenarios/csv_to_postgres/events/orders/data_quality_event.json @@ -10,7 +10,7 @@ "namespace": "postgres://localhost:5432", "facets": { "dataQualityAssertions": { - "assertions": [ + "{{ unordered_list(result, 'assertions') }}": [ { "assertion": "not_null", "name": "not_null_stg_orders_customer_id", diff --git a/scripts/compare_events.py b/scripts/compare_events.py index e358098f..cf960384 100644 --- a/scripts/compare_events.py +++ b/scripts/compare_events.py @@ -1,6 +1,7 @@ # Copyright 2018-2024 contributors to the OpenLineage project # SPDX-License-Identifier: Apache-2.0 +import builtins import json import logging import os @@ -115,7 +116,8 @@ def diff(expected, result, prefix="", function=None) -> list: else: if function == "unordered_list": for i, x in enumerate(expected): - if not any(r for r in result if diff(x, r, f"{prefix}.[{i}]") is []): + # builtins.any: this module defines its own any() as a jinja helper + if not builtins.any(diff(x, r, f"{prefix}.[{i}]") == [] for r in result): errors.append(f"In {prefix}.[{i}], no matching elements") else: for i, x in enumerate(expected):