{"record":{"id":"ca6dbceda1015705","repo":"HumanSignal/label-studio","slug":"range-start-int-requires-one-start-argument","errorCode":null,"errorMessage":"range(start:int) requires one start argument.","messagePattern":"range\\(start:int\\) requires one start argument\\.","errorType":"validation","errorClass":"ValidationError","httpStatus":400,"severity":"error","filePath":"label_studio/data_manager/actions/data_columns.py","lineNumber":289,"sourceCode":"\n\ndef add_expression(queryset, size, value, value_name):\n    if '(' not in value or not value.endswith(')'):\n        raise ValidationError({'value': 'Expression must use the form command(arguments).'})\n    command, args = value.split('(', 1)\n    if not command:\n        raise ValidationError({'value': 'Expression command is required.'})\n    args = process_arrays(args)\n    args = args.replace(')', '').split(',')\n    args = [] if len(args) == 1 and args[0] == '' else args\n    for i, arg in enumerate(args):\n        args[i] = arg.replace(';', ',').replace(\"'\", '\"')\n\n    sample_values = None\n\n    if command == 'range':\n        if len(args) != 1:\n            raise ValidationError({'value': 'range(start:int) requires one start argument.'})\n        start = int(args[0])\n\n    elif command == 'sample':\n        if args:\n            raise ValidationError({'value': 'sample() does not accept arguments.'})\n        sample_values = iter(random.sample(range(0, size), size))\n\n    elif command == 'random':\n        if len(args) != 2:\n            raise ValidationError({'value': 'random(min, max) requires two arguments.'})\n        minimum, maximum = int(args[0]), int(args[1])\n\n    elif command == 'choices':\n        if not 0 < len(args) < 3:\n            raise ValidationError({'value': 'choices(values:list, weights:list) requires one or two arguments.'})\n        weights = json.loads(args[1]) if len(args) == 2 else None\n        choices = json.loads(args[0])\n","sourceCodeStart":271,"sourceCodeEnd":307,"githubUrl":"https://github.com/HumanSignal/label-studio/blob/0b49e9b53917880baf1dd85d574fe5541a9aafb2/label_studio/data_manager/actions/data_columns.py#L271-L307","documentation":"For the 'range' command, add_expression enforces exactly one argument: range(start:int). Supplying zero or multiple arguments raises ValidationError {'value': 'range(start:int) requires one start argument.'}.","triggerScenarios":"Submitting Expression 'range()' (no args), 'range(1, 10)' or 'range(1;10)' (two args — note ';' is converted to ',' before this check), or 'range( 5 , 6 )'.","commonSituations":"User assumes Python-like range(start, stop) semantics and passes two arguments; empty parentheses from the dialog template.","solutions":["Pass exactly one integer argument: 'range(N)' generates a sequence based on task index starting at N.","Remove extra arguments or switch to a different command if a start/stop range is needed.","Cast arguments to int in the payload (they are parsed with int(args[0]))."],"exampleFix":"// before\nvalue = 'range(1, 10)'\n// after\nvalue = 'range(1)'","handlingStrategy":"validation","validationCode":"args_part = value[value.index('(')+1:-1].strip()\nif value.startswith('range'):\n    assert len([a for a in args_part.split(',') if a.strip()]) == 1, 'range takes exactly one int argument'","typeGuard":"import re\ndef is_valid_range_expression(value):\n    return isinstance(value, str) and re.fullmatch(r'range\\(\\s*-?\\d+\\s*\\)', value) is not None","tryCatchPattern":"from rest_framework.exceptions import ValidationError\ntry:\n    add_data_field(project, qs, request=request)\nexcept ValidationError as e:\n    if 'requires one start argument' in str(e):\n        fix_to_single_arg_expression()","preventionTips":["Remember range() here is not Python's range(start, stop) — only one int argument.","Strip whitespace and split arguments the same way the server does before validating.","Show a single numeric input in the UI for the range command."],"tags":["django","validation","data-manager","expression","arguments"],"backgroundTag":"expression-syntax-error","analyzedSha":"0b49e9b53917880baf1dd85d574fe5541a9aafb2","analyzedAt":"2026-08-29T00:39:52.578Z","schemaVersion":2},"datasetVersion":"2026-08-29T02:17:18.158Z"}