{"record":{"id":"afb746a510072034","repo":"redis/redis-py","slug":"must-provide-aggregaterequest-object-or-query-obje","errorCode":null,"errorMessage":"Must provide AggregateRequest object or Query object.","messagePattern":"Must provide AggregateRequest object or Query object\\.","errorType":"validation","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"redis/commands/search/commands.py","lineNumber":1514,"sourceCode":"        **query_params**: Define one or more value parameters.\n        Each parameter has a name and a value.\n\n        \"\"\"\n        st = time.monotonic()\n        cmd = [PROFILE_CMD, self.index_name, \"\"]\n        if limited:\n            cmd.append(\"LIMITED\")\n        cmd.append(\"QUERY\")\n\n        if isinstance(query, AggregateRequest):\n            cmd[2] = \"AGGREGATE\"\n            cmd += query.build_args()\n        elif isinstance(query, Query):\n            cmd[2] = \"SEARCH\"\n            cmd += query.get_args()\n            cmd += self.get_params_args(query_params)\n        else:\n            raise ValueError(\"Must provide AggregateRequest object or Query object.\")\n\n        res = self.execute_command(*cmd)\n\n        return self._parse_results(\n            PROFILE_CMD, res, query=query, duration=(time.monotonic() - st) * 1000.0\n        )\n\n    def spellcheck(self, query, distance=None, include=None, exclude=None):\n        \"\"\"\n        Issue a spellcheck query\n\n        Args:\n\n            query: search query.\n            distance: the maximal Levenshtein distance for spelling\n                       suggestions (default: 1, max: 4).\n            include: specifies an inclusion custom dictionary.\n            exclude: specifies an exclusion custom dictionary.","sourceCodeStart":1496,"sourceCodeEnd":1532,"githubUrl":"https://github.com/redis/redis-py/blob/6a6b581b48225afa0b76912d1028c6035baee932/redis/commands/search/commands.py#L1496-L1532","documentation":"Raised by profile() (redis/commands/search/commands.py:1514) as a ValueError when the query argument is neither an AggregateRequest nor a Query. FT.PROFILE can profile either a SEARCH or an AGGREGATE, so the client requires one of those two typed objects to know which sub-command to issue.","triggerScenarios":"Calling index.profile('*' ), index.profile(None), index.profile({...}), or passing a Cursor (Cursor is valid for aggregate() but not for profile()).","commonSituations":"Passing a raw query string instead of wrapping it in Query(...), or passing an AggregateResult/Cursor where the request object is expected.","solutions":["Wrap strings: index.profile(Query('*')).","For aggregation profiling pass the AggregateRequest itself: index.profile(AggregateRequest('*')).","Do not pass a Cursor or result object - pass the request."],"exampleFix":"# before\nindex.profile('*', limited=True)\n# after\nfrom redis.commands.search.query import Query\nindex.profile(Query('*'), limited=True)","handlingStrategy":"type-guard","validationCode":"from redis.commands.search.query import Query\nfrom redis.commands.search.aggregation import AggregateRequest\n\ndef safe_profile(index, query, limited=False):\n    if not isinstance(query, (Query, AggregateRequest)):\n        raise TypeError('profile() requires a Query or AggregateRequest')\n    return index.profile(query, limited=limited)","typeGuard":"from redis.commands.search.query import Query\nfrom redis.commands.search.aggregation import AggregateRequest\n\ndef is_profile_query(q) -> bool:\n    return isinstance(q, (Query, AggregateRequest))","tryCatchPattern":"try:\n    index.profile(query, limited=True)\nexcept ValueError as e:\n    if 'AggregateRequest object or Query' in str(e):\n        index.profile(Query(str(query)), limited=True)\n    else:\n        raise","preventionTips":["Wrap query strings in Query(...) before profiling.","Pass the AggregateRequest itself (not a Cursor or result) for aggregation profiling.","Keep search and aggregation profiling inputs distinct."],"tags":["search","profile","valueerror","redisearch","argument-validation"],"backgroundTag":null,"analyzedSha":"6a6b581b48225afa0b76912d1028c6035baee932","analyzedAt":"2026-08-10T12:52:44.840Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-21T04:17:39.646Z"}