{"record":{"id":"a77df25d56cb81ba","repo":"makeplane/plane","slug":"invalid-segment-value-segment","errorCode":null,"errorMessage":"Invalid segment value: {segment}","messagePattern":"Invalid segment value: (.+?)","errorType":"exception","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"apps/api/plane/utils/analytics_plot.py","lineNumber":79,"sourceCode":"        return queryset.annotate(dimension=F(x_axis)), \"dimension\"\n\n\ndef sort_data(data, temp_axis):\n    # When the axis is in priority order by\n    if temp_axis == \"priority\":\n        order = [\"low\", \"medium\", \"high\", \"urgent\", \"none\"]\n        return {key: data[key] for key in order if key in data}\n    else:\n        return dict(sorted(data.items(), key=lambda x: (x[0] == \"none\", x[0])))\n\n\ndef build_graph_plot(queryset, x_axis, y_axis, segment=None):\n    if x_axis not in VALID_ANALYTICS_FIELDS:\n        raise ValueError(f\"Invalid x_axis value: {x_axis}\")\n    if y_axis not in VALID_YAXIS:\n        raise ValueError(f\"Invalid y_axis value: {y_axis}\")\n    if segment and segment not in VALID_ANALYTICS_FIELDS:\n        raise ValueError(f\"Invalid segment value: {segment}\")\n\n    # temp x_axis\n    temp_axis = x_axis\n    # Extract the x_axis and queryset\n    queryset, x_axis = extract_axis(queryset, x_axis)\n    if x_axis == \"dimension\":\n        queryset = queryset.exclude(dimension__isnull=True)\n\n    #\n    if segment in [\"created_at\", \"start_date\", \"target_date\", \"completed_at\"]:\n        queryset = annotate_with_monthly_dimension(queryset, segment, \"segmented\")\n        segment = \"segmented\"\n\n    queryset = queryset.values(x_axis)\n\n    # Issue count\n    if y_axis == \"issue_count\":\n        queryset = queryset.annotate(","sourceCodeStart":61,"sourceCodeEnd":97,"githubUrl":"https://github.com/makeplane/plane/blob/1c8a60f858d8472aa56e29994ec1c7926da2c6ce/apps/api/plane/utils/analytics_plot.py#L61-L97","documentation":"ValueError raised by `build_graph_plot` (analytics_plot.py:78) when a non-None `segment` is not in `VALID_ANALYTICS_FIELDS`. segment is optional (None passes silently), but any supplied value must be one of the same 12 lowercase fields allowed for x_axis. The HTTP endpoint additionally rejects segment == x_axis before reaching this code.","triggerScenarios":"Calling build_graph_plot with a segment value that is non-None and not in the 12-field allow-list (e.g. 'segment', 'segments', 'ESTATE', or an uppercase build_chart key). None or omitting segment skips the check.","commonSituations":"Passing a display label instead of a field key for segment; using UPPERCASE keys from build_chart; the export bgtask forwarding an unvalidated segment string.","solutions":["Pass segment as one of the 12 VALID_ANALYTICS_FIELDS strings, or None/omitted.","Ensure segment differs from x_axis (the endpoint enforces this; replicate the check in direct callers).","Validate segment against VALID_ANALYTICS_FIELDS in the bgtask caller before build_graph_plot.","Translate UPPERCASE build_chart keys to their lowercase analytics_plot equivalents."],"exampleFix":"# before\nbuild_graph_plot(qs, x_axis=\"priority\", y_axis=\"issue_count\", segment=\"LABELS\")\n\n# after\nbuild_graph_plot(qs, x_axis=\"priority\", y_axis=\"issue_count\", segment=\"labels__id\")","handlingStrategy":"validation","validationCode":"from plane.utils.analytics_plot import VALID_ANALYTICS_FIELDS\n\ndef is_valid_segment(segment) -> bool:\n    # segment is optional; None is allowed\n    return segment is None or segment in VALID_ANALYTICS_FIELDS","typeGuard":"from plane.utils.analytics_plot import VALID_ANALYTICS_FIELDS\n\ndef is_valid_segment(value) -> bool:\n    return value is None or (isinstance(value, str) and value in VALID_ANALYTICS_FIELDS)","tryCatchPattern":"try:\n    dist = build_graph_plot(qs, x_axis, y_axis, segment)\nexcept ValueError as e:\n    if 'Invalid segment' in str(e):\n        return bad_request(str(e))","preventionTips":["segment must be a VALID_ANALYTICS_FIELDS value or None.","Ensure segment != x_axis (the HTTP endpoint enforces this).","Validate in bgtask callers, not only in the HTTP endpoint."],"tags":["analytics","validation","value-error","api"],"backgroundTag":null,"analyzedSha":"1c8a60f858d8472aa56e29994ec1c7926da2c6ce","analyzedAt":"2026-08-12T14:44:31.636Z","schemaVersion":2},"datasetVersion":"2026-08-12T18:17:37.767Z"}