makeplane/plane · error · ValueError

Invalid segment value: {segment}

Error message

Invalid segment value: {segment}

What it means

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.

Source

Thrown at apps/api/plane/utils/analytics_plot.py:79

        return queryset.annotate(dimension=F(x_axis)), "dimension"


def sort_data(data, temp_axis):
    # When the axis is in priority order by
    if temp_axis == "priority":
        order = ["low", "medium", "high", "urgent", "none"]
        return {key: data[key] for key in order if key in data}
    else:
        return dict(sorted(data.items(), key=lambda x: (x[0] == "none", x[0])))


def build_graph_plot(queryset, x_axis, y_axis, segment=None):
    if x_axis not in VALID_ANALYTICS_FIELDS:
        raise ValueError(f"Invalid x_axis value: {x_axis}")
    if y_axis not in VALID_YAXIS:
        raise ValueError(f"Invalid y_axis value: {y_axis}")
    if segment and segment not in VALID_ANALYTICS_FIELDS:
        raise ValueError(f"Invalid segment value: {segment}")

    # temp x_axis
    temp_axis = x_axis
    # Extract the x_axis and queryset
    queryset, x_axis = extract_axis(queryset, x_axis)
    if x_axis == "dimension":
        queryset = queryset.exclude(dimension__isnull=True)

    #
    if segment in ["created_at", "start_date", "target_date", "completed_at"]:
        queryset = annotate_with_monthly_dimension(queryset, segment, "segmented")
        segment = "segmented"

    queryset = queryset.values(x_axis)

    # Issue count
    if y_axis == "issue_count":
        queryset = queryset.annotate(

View on GitHub (pinned to 1c8a60f858)

Solutions

  1. Pass segment as one of the 12 VALID_ANALYTICS_FIELDS strings, or None/omitted.
  2. Ensure segment differs from x_axis (the endpoint enforces this; replicate the check in direct callers).
  3. Validate segment against VALID_ANALYTICS_FIELDS in the bgtask caller before build_graph_plot.
  4. Translate UPPERCASE build_chart keys to their lowercase analytics_plot equivalents.

Example fix

# before
build_graph_plot(qs, x_axis="priority", y_axis="issue_count", segment="LABELS")

# after
build_graph_plot(qs, x_axis="priority", y_axis="issue_count", segment="labels__id")
Defensive patterns

Strategy: validation

Validate before calling

from plane.utils.analytics_plot import VALID_ANALYTICS_FIELDS

def is_valid_segment(segment) -> bool:
    # segment is optional; None is allowed
    return segment is None or segment in VALID_ANALYTICS_FIELDS

Type guard

from plane.utils.analytics_plot import VALID_ANALYTICS_FIELDS

def is_valid_segment(value) -> bool:
    return value is None or (isinstance(value, str) and value in VALID_ANALYTICS_FIELDS)

Try / catch

try:
    dist = build_graph_plot(qs, x_axis, y_axis, segment)
except ValueError as e:
    if 'Invalid segment' in str(e):
        return bad_request(str(e))

Prevention

When it happens

Trigger: 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.

Common situations: 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.

Related errors


AI-assisted analysis of makeplane/plane@1c8a60f858 (2026-08-12). Data as JSON: /api/errors/a77df25d56cb81ba. Report an issue: GitHub.