Skip to content

:hedgehog: PostHog is the leading platform for building self-driving products. Our developer tools – AI observability, analytics, session replay, flags, experiments, error tracking, logs, and more – capture all the context agents need to diagnose problems, uncover opportunities, and ship fixes. Steer it all from Slack, web, desktop, or the MCP.

fix(filters): Accept bool in temporal inputs (#110859)

Tomás Farías Santana400cc667daa8
diff --git a/products/batch_exports/backend/service.py b/products/batch_exports/backend/service.py
index 7c478bc6a2a0..a22d7d5e1366 100644
--- a/products/batch_exports/backend/service.py
+++ b/products/batch_exports/backend/service.py
@@ -152,7 +152,7 @@ class BatchExportEventPropertyFilter:
class BatchExportModel:
name: str
schema: BatchExportSchema | None
- filters: list[dict[str, str | list[str] | None]] | None = None
+ filters: list[dict[str, str | bool | list[str] | None]] | None = None
hogql_query: str | None = None
# The user who last modified the batch export. This is used for validating custom HogQL queries. This is stored alongside the query, not looked up at runtime, so that an edit during a run cannot pair the old query with a new user.
user_id: int | None = None
diff --git a/products/batch_exports/backend/temporal/filters.py b/products/batch_exports/backend/temporal/filters.py
index f1ac83109f21..db74d6253dc9 100644
--- a/products/batch_exports/backend/temporal/filters.py
+++ b/products/batch_exports/backend/temporal/filters.py
@@ -58,7 +58,7 @@ class InvalidFilterError(Exception):
def compose_filters_clause(
- filters: list[dict[str, str | list[str] | None]],
+ filters: list[dict[str, str | bool | list[str] | None]],
team_id: int,
values: dict[str, str] | None = None,
*,
diff --git a/products/batch_exports/backend/temporal/pipeline/internal_stage.py b/products/batch_exports/backend/temporal/pipeline/internal_stage.py
index 44cfb03e37f8..b1f11f4f5ea3 100644
--- a/products/batch_exports/backend/temporal/pipeline/internal_stage.py
+++ b/products/batch_exports/backend/temporal/pipeline/internal_stage.py
@@ -415,7 +415,7 @@ async def _stage_query_results(
record_batch_model: RecordBatchModel | None,
model_name: str,
fields: list[BatchExportField] | None,
- filters: list[dict[str, str | list[str] | None]] | None,
+ filters: list[dict[str, str | bool | list[str] | None]] | None,
extra_query_parameters: dict[str, typing.Any] | None,
full_range: tuple[dt.datetime | None, dt.datetime | None],
s3_staging_folder: S3StagingFolder,
@@ -539,7 +539,7 @@ async def _get_query(
data_interval_end: str,
fields: list[BatchExportField] | None = None,
destination_default_fields: list[BatchExportField] | None = None,
- filters: list[dict[str, str | list[str] | None]] | None = None,
+ filters: list[dict[str, str | bool | list[str] | None]] | None = None,
num_partitions: int | None = None,
is_workflows: bool = False,
**parameters,
diff --git a/products/batch_exports/backend/tests/temporal/destinations/test_http_batch_export_workflow.py b/products/batch_exports/backend/tests/temporal/destinations/test_http_batch_export_workflow.py
index bdb43bbc8a9d..e6fd9dca855e 100644
--- a/products/batch_exports/backend/tests/temporal/destinations/test_http_batch_export_workflow.py
+++ b/products/batch_exports/backend/tests/temporal/destinations/test_http_batch_export_workflow.py
@@ -85,7 +85,7 @@ async def assert_clickhouse_records_in_mock_server(
exclude_events: list[str] | None = None,
include_events: list[str] | None = None,
backfill_details: BackfillDetails | None = None,
- filters: list[dict[str, str | list[str] | None]] | None = None,
+ filters: list[dict[str, str | bool | list[str] | None]] | None = None,
):
"""Assert expected records are written to a MockServer instance."""
posted_records = mock_server.records
diff --git a/products/batch_exports/backend/tests/temporal/utils/clickhouse_test_producer.py b/products/batch_exports/backend/tests/temporal/utils/clickhouse_test_producer.py
index 7740e50722b7..ce3fa6673fb0 100644
--- a/products/batch_exports/backend/tests/temporal/utils/clickhouse_test_producer.py
+++ b/products/batch_exports/backend/tests/temporal/utils/clickhouse_test_producer.py
@@ -147,7 +147,7 @@ class ClickHouseTestProducer:
destination_default_fields: list[BatchExportField] | None = None,
max_record_batch_size_bytes: int = 0,
min_records_per_batch: int = 100,
- filters: list[dict[str, str | list[str] | None]] | None = None,
+ filters: list[dict[str, str | bool | list[str] | None]] | None = None,
order_columns: collections.abc.Iterable[str] | None = ("_inserted_at", "event"),
is_workflows: bool = False,
**parameters,
diff --git a/products/batch_exports/backend/tests/test_service.py b/products/batch_exports/backend/tests/test_service.py
index 9a4c51670fe7..956174e8a9cc 100644
--- a/products/batch_exports/backend/tests/test_service.py
+++ b/products/batch_exports/backend/tests/test_service.py
@@ -3,6 +3,8 @@ import datetime as dt
import pytest
+from temporalio.converter import JSONPlainPayloadConverter
+
from products.batch_exports.backend.models.batch_export import (
BatchExport,
BatchExportBackfill,
@@ -12,6 +14,7 @@ from products.batch_exports.backend.models.batch_export import (
from products.batch_exports.backend.service import (
AWSCredentials,
AzureBlobBatchExportInputs,
+ BatchExportModel,
BigQueryBatchExportInputs,
DatabricksBatchExportInputs,
PostgresBatchExportInputs,
@@ -110,7 +113,8 @@ class TestTypeCoercionInBatchExportInputs:
def test_string_ints_are_coerced(self, destination, field, expected):
assert getattr(DESTINATION_INPUTS[destination], field) == expected
- def test_actual_booleans_are_preserved(self):
+ @pytest.mark.parametrize("filter_value", [True, False])
+ def test_actual_booleans_are_preserved(self, filter_value: bool) -> None:
inputs = DatabricksBatchExportInputs(
batch_export_id="test",
team_id=1,
@@ -120,9 +124,22 @@ class TestTypeCoercionInBatchExportInputs:
table_name="events",
use_variant_type=True,
use_automatic_schema_evolution=False,
+ batch_export_model=BatchExportModel(
+ name="events",
+ schema=None,
+ filters=[{"type": "hogql", "key": "event = 'example_event'", "value": filter_value}],
+ ),
)
+ converter = JSONPlainPayloadConverter()
+ payload = converter.to_payload(inputs)
+ assert payload is not None
+ inputs = converter.from_payload(payload, DatabricksBatchExportInputs)
+
assert inputs.use_variant_type is True
assert inputs.use_automatic_schema_evolution is False
+ assert inputs.batch_export_model is not None
+ assert inputs.batch_export_model.filters is not None
+ assert inputs.batch_export_model.filters[0]["value"] is filter_value
def test_optional_int_none_is_preserved(self):
inputs = S3BatchExportInputs(