{"record":{"id":"1a4861e89e6028a9","repo":"redis/redis-py","slug":"did-not-receive-a-filter-object","errorCode":null,"errorMessage":"Did not receive a Filter object.","messagePattern":"Did not receive a Filter object\\.","errorType":"validation","errorClass":"AttributeError","httpStatus":null,"severity":"error","filePath":"redis/commands/search/query.py","lineNumber":217,"sourceCode":"        args += [\"LIMIT\", self._offset, self._num]\n        return args\n\n    def _get_args_tags(self) -> List[Union[str, int, float]]:\n        args: List[Union[str, int, float]] = []\n        if self._no_content:\n            args.append(\"NOCONTENT\")\n        if self._fields:\n            args.append(\"INFIELDS\")\n            args.append(len(self._fields))\n            args += self._fields\n        if self._verbatim:\n            args.append(\"VERBATIM\")\n        if self._no_stopwords:\n            args.append(\"NOSTOPWORDS\")\n        if self._filters:\n            for flt in self._filters:\n                if not isinstance(flt, Filter):\n                    raise AttributeError(\"Did not receive a Filter object.\")\n                args += flt.args\n        if self._with_payloads:\n            args.append(\"WITHPAYLOADS\")\n        if self._scorer:\n            args += [\"SCORER\", self._scorer]\n        if self._with_scores:\n            args.append(\"WITHSCORES\")\n        if self._ids:\n            args.append(\"INKEYS\")\n            args.append(len(self._ids))\n            args += self._ids\n        if self._slop >= 0:\n            args += [\"SLOP\", self._slop]\n        if self._timeout is not None:\n            args += [\"TIMEOUT\", self._timeout]\n        if self._in_order:\n            args.append(\"INORDER\")\n        if self._return_fields:","sourceCodeStart":199,"sourceCodeEnd":235,"githubUrl":"https://github.com/redis/redis-py/blob/6a6b581b48225afa0b76912d1028c6035baee932/redis/commands/search/query.py#L199-L235","documentation":"Raised during Query.get_args() / _get_args_tags() when an entry in the query's filter list is not an instance of redis.commands.search.query.Filter (NumericFilter or GeoFilter). Query.add_filter accepts any object, so a wrong type is caught only at argument-serialization time.","triggerScenarios":"Calling query.add_filter(x) where x is a raw tuple, dict, string, or None instead of a Filter subclass. Mutating Query._filters directly with non-Filter items.","commonSituations":"Passing a querystring filter expression instead of the Filter object. Copy-paste from examples that build filters inline. Storing filters in a list and appending the wrong shape.","solutions":["Pass a NumericFilter or GeoFilter instance to add_filter, e.g. query.add_filter(NumericFilter('price', 0, 100)).","If you have a raw querystring expression, put it in the Query's query string instead of add_filter.","Build filters via the documented helper classes (GeoFilter, NumericFilter) rather than tuples."],"exampleFix":"// before\nquery.add_filter(('FILTER', 'price', 0, 100))\n// after\nfrom redis.commands.search.query import NumericFilter\nquery.add_filter(NumericField('price', 0, 100))\n# correct class name:\nquery.add_filter(NumericFilter('price', 0, 100))","handlingStrategy":"type-guard","validationCode":"from redis.commands.search.query import Filter\nfor flt in filters:\n    assert isinstance(flt, Filter), f'expected Filter, got {type(flt)}'\n    query.add_filter(flt)","typeGuard":"from redis.commands.search.query import Filter\n\ndef is_filter(f) -> bool:\n    return isinstance(f, Filter)","tryCatchPattern":"try:\n    query.get_args()\nexcept AttributeError as e:\n    if 'Filter object' in str(e):\n        # rebuild filters as Filter instances\n        raise\n    raise","preventionTips":["Always build filters with NumericFilter / GeoFilter constructors.","Do not store raw tuples in Query._filters."],"tags":["redisearch","query","argument-validation"],"backgroundTag":null,"analyzedSha":"6a6b581b48225afa0b76912d1028c6035baee932","analyzedAt":"2026-08-10T12:52:44.840Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-21T04:17:39.646Z"}