{"record":{"id":"44edb7cd7aba8bd1","repo":"pytest-dev/pytest","slug":"error-raised-while-trying-to-determine-id-of-param","errorCode":null,"errorMessage":"error raised while trying to determine id of parameter '{argname}' at position {idx}","messagePattern":"error raised while trying to determine id of parameter '(.+?)' at position (.+?)","errorType":"exception","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"src/_pytest/python.py","lineNumber":1086,"sourceCode":"                    f\"{prefix}parametrize value for '{argname}' at index {idx} \"\n                    f\"is too long for an auto-generated ID ({len(val)} characters). \"\n                    f\"Use pytest.param(..., id=...) or parametrize(..., ids=...) \"\n                    f\"to set an explicit ID, or change parametrize_long_str_id_strategy.\",\n                    pytrace=False,\n                )\n\n    def _idval_from_function(self, val: object, argname: str, idx: int) -> str | None:\n        \"\"\"Try to make an ID for a parameter in a ParameterSet using the\n        user-provided id callable, if given.\"\"\"\n        if self.idfn is None:\n            return None\n        try:\n            id = self.idfn(val)\n        except Exception as e:\n            prefix = f\"{self.nodeid}: \" if self.nodeid is not None else \"\"\n            msg = \"error raised while trying to determine id of parameter '{}' at position {}\"\n            msg = prefix + msg.format(argname, idx)\n            raise ValueError(msg) from e\n        if id is None:\n            return None\n        return self._idval_from_value(id)\n\n    def _idval_from_hook(self, val: object, argname: str) -> str | None:\n        \"\"\"Try to make an ID for a parameter in a ParameterSet by calling the\n        :hook:`pytest_make_parametrize_id` hook.\"\"\"\n        if self.config:\n            id: str | None = self.config.hook.pytest_make_parametrize_id(\n                config=self.config, val=val, argname=argname\n            )\n            return id\n        return None\n\n    def _idval_from_value(self, val: object) -> str | None:\n        \"\"\"Try to make an ID for a parameter in a ParameterSet from its value,\n        if the value type is supported.\"\"\"\n        match val:","sourceCodeStart":1068,"sourceCodeEnd":1104,"githubUrl":"https://github.com/pytest-dev/pytest/blob/0d6fbdeffa57c796123f62f81f7dd370d9b7ecdc/src/_pytest/python.py#L1068-L1104","documentation":"Thrown by IdMaker._idval_from_function() when the user-supplied `ids` callable (idfn) raises an exception while computing an id for a parameter value. The original exception is chained as `from e` and the argname/idx are included for context.","triggerScenarios":"Passing ids=lambda v: v.lower() to @pytest.mark.parametrize where some parameter value is None or an int; an idfn that does dict lookups on missing keys; an idfn that calls a buggy helper.","commonSituations":"Parametrizing with mixed types and a naive idfn; idfn that assumes all values share a shape; refactor introducing None as a param value.","solutions":["Make the idfn defensive: return None for unsupported types so pytest falls back to auto-generated ids.","Fix the bug in the idfn that raised.","Use pytest.param(..., id='name') to set ids explicitly for problematic values."],"exampleFix":"// before\n@pytest.mark.parametrize(\"x\", [None, \"a\", 1], ids=lambda v: v.lower())\n// after\n@pytest.mark.parametrize(\"x\", [None, \"a\", 1], ids=lambda v: v.lower() if isinstance(v, str) else None)","handlingStrategy":"try-catch","validationCode":"def safe_idfn(v):\n    try:\n        return idfn(v)\n    except Exception:\n        return None  # fall back to auto-generated id","typeGuard":null,"tryCatchPattern":"try:\n    @pytest.mark.parametrize('x', values, ids=my_idfn)\n    def test_x(x): ...\nexcept ValueError as e:\n    if 'error raised while trying to determine id' in str(e):\n        # fix idfn to be defensive, then retry\n        pass\n    raise","preventionTips":["Write defensive idfn that returns None for unknown types.","Use pytest.param(..., id=...) for explicit ids on tricky values.","Test idfn in isolation across all parametrized values."],"tags":["parametrize","idfn","callable","validation"],"backgroundTag":null,"analyzedSha":"0d6fbdeffa57c796123f62f81f7dd370d9b7ecdc","analyzedAt":"2026-08-11T20:52:36.969Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-14T00:17:10.932Z"}