{"record":{"id":"befc22cc7e97b9f4","repo":"redis/redis-py","slug":"index-type-must-be-one-of-list-indextype","errorCode":null,"errorMessage":"index_type must be one of {list(IndexType)}","messagePattern":"index_type must be one of (.+?)","errorType":"validation","errorClass":"RuntimeError","httpStatus":null,"severity":"error","filePath":"redis/commands/search/index_definition.py","lineNumber":43,"sourceCode":"        payload_field=None,\n        index_type=None,\n    ):\n        self.args = []\n        self._append_index_type(index_type)\n        self._append_prefix(prefix)\n        self._append_filter(filter)\n        self._append_language(language_field, language)\n        self._append_score(score_field, score)\n        self._append_payload(payload_field)\n\n    def _append_index_type(self, index_type):\n        \"\"\"Append `ON HASH` or `ON JSON` according to the enum.\"\"\"\n        if index_type is IndexType.HASH:\n            self.args.extend([\"ON\", \"HASH\"])\n        elif index_type is IndexType.JSON:\n            self.args.extend([\"ON\", \"JSON\"])\n        elif index_type is not None:\n            raise RuntimeError(f\"index_type must be one of {list(IndexType)}\")\n\n    def _append_prefix(self, prefix):\n        \"\"\"Append PREFIX.\"\"\"\n        if prefix is None:\n            raise TypeError(\"prefix must be provided\")\n        if len(prefix) > 0:\n            prefix = list_or_args(prefix, [])\n            self.args.append(\"PREFIX\")\n            self.args.append(len(prefix))\n            for p in prefix:\n                self.args.append(p)\n\n    def _append_filter(self, filter):\n        \"\"\"Append FILTER.\"\"\"\n        if filter is not None:\n            self.args.append(\"FILTER\")\n            self.args.append(filter)\n","sourceCodeStart":25,"sourceCodeEnd":61,"githubUrl":"https://github.com/redis/redis-py/blob/6a6b581b48225afa0b76912d1028c6035baee932/redis/commands/search/index_definition.py#L25-L61","documentation":"Raised by IndexDefinition._append_index_type() (redis/commands/search/index_definition.py:43) as a RuntimeError when index_type is not None, IndexType.HASH, or IndexType.JSON. Crucially the checks use identity (is), so passing the strings 'HASH' or 'JSON' does NOT match - you must pass the enum member. The message prints list(IndexType) which renders as [<IndexType.HASH: 1>, <IndexType.JSON: 2>] rather than friendly strings.","triggerScenarios":"Calling IndexDefinition(index_type='HASH'), IndexDefinition(index_type='json'), or any non-enum value. Passing IndexType.HASH or IndexType.JSON works; passing the raw string does not.","commonSituations":"Reading index type from config as a string and passing it directly, or assuming the constructor accepts strings like other parts of the API. The unhelpful message rendering makes the fix non-obvious.","solutions":["Import and pass the enum: from redis.commands.search.index_definition import IndexType; IndexDefinition(index_type=IndexType.HASH).","If your config is a string, map it: IndexType[config_str.upper()].","Omit index_type (None) if you want the server default."],"exampleFix":"# before\nIndexDefinition(prefix=['doc:'], index_type='JSON')\n# after\nfrom redis.commands.search.index_definition import IndexType\nIndexDefinition(prefix=['doc:'], index_type=IndexType.JSON)","handlingStrategy":"type-guard","validationCode":"from redis.commands.search.index_definition import IndexType, IndexDefinition\n\ndef safe_index_type(value):\n    if value is None or isinstance(value, IndexType):\n        return value\n    if isinstance(value, str):\n        return IndexType[value.upper()]\n    raise ValueError('index_type must be IndexType.HASH, IndexType.JSON, or None')","typeGuard":"from redis.commands.search.index_definition import IndexType\n\ndef is_valid_index_type(v) -> bool:\n    return v is None or isinstance(v, IndexType)","tryCatchPattern":"try:\n    IndexDefinition(prefix=['doc:'], index_type=it)\nexcept RuntimeError as e:\n    if 'index_type' in str(e):\n        IndexDefinition(prefix=['doc:'], index_type=IndexType[it.upper()])\n    else:\n        raise","preventionTips":["Always pass the IndexType enum member, never a raw string.","Map config strings via IndexType[config_str.upper()].","Omit index_type for the server default."],"tags":["search","index-definition","runtimeerror","redisearch","enum"],"backgroundTag":null,"analyzedSha":"6a6b581b48225afa0b76912d1028c6035baee932","analyzedAt":"2026-08-10T12:52:44.840Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-21T04:17:39.646Z"}