pathwaycom/pathway · error · TypeError

Expected 'is_upsert' to be of type 'bool', got '{is_upsert_t

Error message

Expected 'is_upsert' to be of type 'bool', got '{is_upsert_type.typehint}'

What it means

Raised by Table.stream_to_table() when the is_upsert expression's dtype is not exactly dt.BOOL. stream_to_table collapses an update stream into a table using this boolean flag to decide whether each message is an insertion or a deletion, so a strictly bool-typed expression is mandatory.

Source

Thrown at python/pathway/internals/table.py:2955

        ... id | pet | age | is_upsert | __time__
        ...  1 | cat |  3  |   True    |     2
        ...  2 | dog | 11  |   True    |     2
        ...  1 | cat | 4   |   True    |     4
        ...  2 | dog | 0   |  False    |     4
        ... '''
        ... )
        >>> t2 = t1.stream_to_table(pw.this.is_upsert)
        >>> pw.debug.compute_and_print_update_stream(t2, include_id=False)
        pet | age | is_upsert | __time__ | __diff__
        cat | 3   | True      | 2        | 1
        dog | 11  | True      | 2        | 1
        cat | 3   | True      | 4        | -1
        dog | 11  | True      | 4        | -1
        cat | 4   | True      | 4        | 1
        """
        is_upsert_type = self.eval_type(is_upsert)
        if is_upsert_type != dt.BOOL:
            raise TypeError(
                f"Expected 'is_upsert' to be of type 'bool', got '{is_upsert_type.typehint}'"
            )
        self._validate_expression(is_upsert)
        is_upsert_column = self._eval(is_upsert)
        assert self._universe == is_upsert_column.universe
        context = clmn.StreamToTableContext(self._id_column, is_upsert_column)
        return self._table_with_context(context)

    @trace_user_frame
    @contextualized_operator
    @check_arg_types
    def from_streams(self, deletion_stream: Table) -> Table[TSchema]:
        """
        Converts streams of changes (updates and deletions) into a table.

        This method reconstructs the current state of the table from such streams by applying the updates
        and deletions in order. It is a stateful operation: the operator keeps track of the latest value for each id.
        If there are multiple events for a single id in a single batch in the input streams, the order of applying

View on GitHub (pinned to fa2f74a464)

Solutions

  1. Cast the column to bool: t.stream_to_table(pw.this.flag.cast(bool))
  2. Fix the schema so the column is declared bool: flag: bool in the connector's Schema class
  3. If the flag is int 0/1, convert explicitly: t.stream_to_table(pw.this.flag == 1)
  4. Verify dtype before the call: t.eval_type(pw.this.flag) must print bool

Example fix

# before
t2 = t.stream_to_table(pw.this.flag)  # flag: int -> TypeError

# after
t2 = t.stream_to_table(pw.this.flag == 1)
# or
t2 = t.stream_to_table(pw.this.flag.cast(bool))
Defensive patterns

Strategy: type-guard

Validate before calling

import pathway as pw

def upsert_is_bool(t, expr) -> bool:
    return t.eval_type(expr) == pw.schema_dtypes().get('bool') or str(t.eval_type(expr)) == 'bool'
# simpler: t.eval_type(expr) must equal dt.BOOL

Type guard

def is_bool_expr(t, expr) -> bool:
    from pathway.internals.dtype import dtypes as dt
    return t.eval_type(expr) == dt.BOOL

Try / catch

try:
    t2 = t.stream_to_table(pw.this.flag)
except TypeError as e:
    if "'is_upsert'" in str(e):
        t2 = t.stream_to_table(pw.this.flag.cast(bool))

Prevention

When it happens

Trigger: t.stream_to_table(pw.this.flag) where flag is int (0/1), str ('true'), Optional[bool], or Any-typed; passing a raw column from a connector that does not declare bool.

Common situations: Kafka/message-queue connectors delivering 0/1 or 'true'/'false' flags; schemas declared with int or Any for the upsert column; older Pathway versions being more lenient with type coercion.

Related errors


AI-assisted analysis of pathwaycom/pathway@fa2f74a464 (2026-08-15). Data as JSON: /api/errors/54666ae73e509a43. Report an issue: GitHub.