{"record":{"id":"96b64dd2ed6ab7dc","repo":"apache/beam","slug":"s-filters-must-be-a-sequence-of-tuple-with-length-3-got-r","errorCode":null,"errorMessage":"%s: filters must be a sequence of tuple with length=3 got %r instead","messagePattern":"(.+?): filters must be a sequence of tuple with length=3 got %r instead","errorType":"validation","errorClass":"TypeError","httpStatus":null,"severity":"error","filePath":"sdks/python/apache_beam/io/gcp/datastore/v1new/types.py","lineNumber":120,"sourceCode":"        kind=self.kind,\n        project=self.project,\n        namespace=self.namespace,\n        ancestor=ancestor_client_key,\n        filters=self.filters,\n        projection=self.projection,\n        order=self.order,\n        distinct_on=self.distinct_on)\n\n  def _set_runtime_filters(self):\n    \"\"\"\n    Extracts values from ValueProviders in `self.filters` if available\n    :param filters: sequence of tuple[str, str, str] or\n    sequence of tuple[ValueProvider, ValueProvider, ValueProvider]\n    :return: tuple[str, str, str]\n    \"\"\"\n    runtime_filters = []\n    if not all(len(filter_tuple) == 3 for filter_tuple in self.filters):\n      raise TypeError(\n          '%s: filters must be a sequence of tuple with length=3'\n          ' got %r instead' % (self.__class__.__name__, self.filters))\n\n    for filter_type, filter_operator, filter_value in self.filters:\n      if isinstance(filter_type, ValueProvider):\n        filter_type = filter_type.get()\n      if isinstance(filter_operator, ValueProvider):\n        filter_operator = filter_operator.get()\n      if isinstance(filter_value, ValueProvider):\n        filter_value = filter_value.get()\n      runtime_filters.append((filter_type, filter_operator, filter_value))\n\n    return runtime_filters or ()\n\n  def clone(self):\n    return copy.copy(self)\n\n  def __repr__(self):","sourceCodeStart":102,"sourceCodeEnd":138,"githubUrl":"https://github.com/apache/beam/blob/12126d8942aaf848030c478b4c6a28c6af861c66/sdks/python/apache_beam/io/gcp/datastore/v1new/types.py#L102-L138","documentation":"When converting a Beam Query for the Cloud Datastore v1 client, each filter must be a 3-tuple (property, operator, value). _set_runtime_filters checks every tuple has length exactly 3 and raises TypeError otherwise, because a malformed filter cannot be mapped onto the structured-query proto.","triggerScenarios":"Building Query(..., filters=[...]) with a tuple of length 1, 2, or 4 (e.g. forgetting the value: ('age', '>')), passing a non-iterable filter, or appending filters of the wrong shape at runtime via _to_client_query.","commonSituations":"Migrating from other Datastore client libraries where filters are method calls (add_filter(prop, op, value)) rather than tuples; developers port code and pass 2-tuples, or build filters dynamically and accidentally drop an element.","solutions":["Ensure every entry in query.filters is a (property, operator, value) 3-tuple.","If the value is missing, supply it or use an operator form that takes one, e.g. ('age', '>', 0).","When using templates, each element may be a ValueProvider, but the tuple itself must still have exactly three ValueProvider/str elements.","Validate filters at pipeline-construction time with a small assertion loop before creating the Query."],"exampleFix":"// before\nquery = Query(kind='Person', filters=[('age', '>')])\n// after\nquery = Query(kind='Person', filters=[('age', '>', 30)])","handlingStrategy":"validation","validationCode":"def check_filters(filters):\n    for f in filters:\n        if not (isinstance(f, tuple) and len(f) == 3):\n            raise TypeError(f'Filter must be (prop, op, value) 3-tuple, got {f!r}')","typeGuard":null,"tryCatchPattern":"try:\n    client_query = query._to_client_query()\nexcept TypeError as e:\n    raise PipelineError(f'Malformed Datastore filters: {e}') from e","preventionTips":["Always build filters as (property, operator, value) tuples","Keep ValueProviders inside the tuple, not as the tuple itself","Assert filter shape in unit tests for template pipelines"],"tags":["type-error","query-validation","google-cloud-datastore"],"backgroundTag":"invalid-argument-format","analyzedSha":"12126d8942aaf848030c478b4c6a28c6af861c66","analyzedAt":"2026-09-13T01:50:10.254Z","contentChangedAt":"2026-09-13T01:50:10.254Z","schemaVersion":2},"datasetVersion":"2026-09-20T03:17:13.778Z"}