Skip to content

Instantly share code, notes, and snippets.

@gibsondan
Last active April 17, 2026 22:17
Show Gist options
  • Select an option

  • Save gibsondan/6d0c483f8499a8b1cd460cddc9fd8f72 to your computer and use it in GitHub Desktop.

Select an option

Save gibsondan/6d0c483f8499a8b1cd460cddc9fd8f72 to your computer and use it in GitHub Desktop.

Backport: Escape single quotes in static partition keys for DB IO managers

If you are using one of the affected IO managers (Snowflake, BigQuery, DuckDB, DeltaLake) on Dagster >= 1.1.21 (dagster-snowflake / dagster-gcp / dagster-duckdb >= 0.17.21, any dagster-deltalake), see the instructions below to mitigate this issue in existing code without needing to upgrade.

Save the relevant snippet(s) in your project and import them once, at the top of your definitions.py, before any IO manager is instantiated. Each snippet is independent — apply only the ones matching the IO managers you use.


dagster-snowflake

from dagster_snowflake import snowflake_io_manager

def _safe_static_where_clause(table_partition):
    partitions = ", ".join(
        "'" + str(p).replace("'", "''") + "'" for p in table_partition.partitions
    )
    return f"{table_partition.partition_expr} in ({partitions})"

snowflake_io_manager._static_where_clause = _safe_static_where_clause

dagster-gcp (BigQuery)

from dagster_gcp.bigquery import io_manager as bq_io_manager

def _safe_static_where_clause(table_partition):
    partitions = ", ".join(
        "'" + str(p).replace("'", "''") + "'" for p in table_partition.partitions
    )
    return f"{table_partition.partition_expr} in ({partitions})"

bq_io_manager._static_where_clause = _safe_static_where_clause

dagster-duckdb

from dagster_duckdb import io_manager as duckdb_io_manager

def _safe_static_where_clause(table_partition):
    partitions = ", ".join(
        "'" + str(p).replace("'", "''") + "'" for p in table_partition.partitions
    )
    return f"{table_partition.partition_expr} in ({partitions})"

duckdb_io_manager._static_where_clause = _safe_static_where_clause

dagster-deltalake

from dagster_deltalake import io_manager as delta_io_manager
from dagster_deltalake import handler as delta_handler

def _safe_static_where_clause(table_partition):
    partitions = ", ".join(
        "'" + str(p).replace("'", "''") + "'" for p in table_partition.partitions
    )
    return f"{table_partition.partition_expr} in ({partitions})"

def _safe_format_predicate_value(value):
    if value is None:
        return None
    if hasattr(value, "strftime"):
        formatted = value.strftime("%Y-%m-%d")
        return "'" + formatted.replace("'", "''") + "'"
    if isinstance(value, str):
        return "'" + value.replace("'", "''") + "'"
    raise ValueError(f"Unsupported partition predicate value type: {type(value).__name__}")

delta_io_manager._static_where_clause = _safe_static_where_clause
delta_handler._format_predicate_value = _safe_format_predicate_value

Comments are disabled for this gist.