{"record":{"id":"cc349e98c33baad9","repo":"HumanSignal/label-studio","slug":"incorrect-value-type-in-key-key-value-i","errorCode":null,"errorMessage":"Incorrect value type in key \"{key}\" = \"{value}\". It should be digit string or integer.","messagePattern":"Incorrect value type in key \"(.+?)\" = \"(.+?)\"\\. It should be digit string or integer\\.","errorType":"validation","errorClass":"ValidationError","httpStatus":null,"severity":"error","filePath":"label_studio/core/utils/params.py","lineNumber":59,"sourceCode":"    :param default: default value\n    :return: int\n    \"\"\"\n    value = params.get(key, default)\n\n    # str\n    if isinstance(value, str):\n        try:\n            return int(value)\n        except ValueError:\n            raise ValidationError({key: f'Incorrect value in key \"{key}\" = \"{value}\". It should be digit string.'})\n        except Exception as e:\n            raise ValidationError({key: str(e)})\n    # int\n    elif isinstance(value, int):\n        return value\n    # other\n    else:\n        raise ValidationError(\n            {key: f'Incorrect value type in key \"{key}\" = \"{value}\". It should be digit string or integer.'}\n        )\n\n\ndef float_from_request(params, key, default):\n    \"\"\"Get float from request GET, POST, etc\n\n    :param params: dict POST, GET, etc\n    :param key: key to find\n    :param default: default value\n    :return: float\n    \"\"\"\n    value = params.get(key, default)\n\n    # str\n    if isinstance(value, str):\n        try:\n            return float(value)","sourceCodeStart":41,"sourceCodeEnd":77,"githubUrl":"https://github.com/HumanSignal/label-studio/blob/0b49e9b53917880baf1dd85d574fe5541a9aafb2/label_studio/core/utils/params.py#L41-L77","documentation":"int_from_request validates that a request parameter (GET/POST) identified by `key` is an integer or a digit-only string. If the value is any other type (e.g. list, dict, bool, float), it raises Django's ValidationError. This guards request-param parsing paths (pagination, task ops) against type confusion.","triggerScenarios":"Calling an endpoint that uses int_from_request (e.g. paginators, get/post handlers like get_prepare_params) with a query/body param whose value is neither a str nor int — e.g. passing a float like 1.5, a list, or a nested object as the parameter.","commonSituations":"API clients sending `page=1.5` or JSON-typed values in query params; frontends sending arrays for repeated keys (`?page=1&page=2`) which Django parses into a list; automated scripts passing Python objects instead of scalar strings.","solutions":["Inspect the request and make sure the offending `key` param is sent once, as a plain digit string or integer (e.g. `page=3`).","Client-side: convert the value with str(int(x)) before sending instead of passing floats/lists/bools.","If a float is legitimately needed, use the float_from_request helper endpoint behavior instead of int parsing.","Catch the raised ValidationError in the endpoint and return a 400 with the field key so the client can correct it."],"exampleFix":"// before\ncurl '/api/tasks?page=1.5'\n\n// after\ncurl '/api/tasks?page=1'","handlingStrategy":"validation","validationCode":"def ensure_int_param(params, key):\n    value = params.get(key)\n    if isinstance(value, list):\n        value = value[0] if len(value) == 1 else None\n    if not isinstance(value, (str, int)) or (isinstance(value, str) and not value.isdigit()):\n        raise ValueError(f'{key} must be a digit string or integer')\n    return int(value)","typeGuard":"def is_int_like(value) -> bool:\n    return isinstance(value, int) or (isinstance(value, str) and value.isdigit())","tryCatchPattern":"from rest_framework.exceptions import ValidationError\ntry:\n    page = int_from_request(request.GET, 'page', 1)\nexcept ValidationError as e:\n    return Response({'detail': 'invalid integer param', 'errors': e.detail}, status=400)","preventionTips":["Always send scalar values once in query params; avoid repeated keys for scalar fields","Cast numbers with str(int(x)) on the client before sending","Keep float/bool values out of int-typed parameters"],"tags":["request-validation","django","parameter-type","validation"],"backgroundTag":"invalid-request-parameter-type","analyzedSha":"0b49e9b53917880baf1dd85d574fe5541a9aafb2","analyzedAt":"2026-08-29T00:39:52.578Z","schemaVersion":2},"datasetVersion":"2026-08-29T02:17:18.158Z"}