Skip to content

:hedgehog: PostHog is the leading platform for building self-driving products. Our developer tools – AI observability, analytics, session replay, flags, experiments, error tracking, logs, and more – capture all the context agents need to diagnose problems, uncover opportunities, and ship fixes. Steer it all from Slack, web, desktop, or the MCP.

fix(experiments): set output_field when ordering experiments by created_by (#65700)

Juraj Majerik0e0644e3d9f8
diff --git a/products/experiments/backend/experiment_service.py b/products/experiments/backend/experiment_service.py
index e17d7dd858b5..1da1825b7716 100644
--- a/products/experiments/backend/experiment_service.py
+++ b/products/experiments/backend/experiment_service.py
@@ -10,7 +10,7 @@ from uuid import uuid4
from zoneinfo import ZoneInfo
from django.db import transaction
-from django.db.models import Case, Count, F, Prefetch, Q, QuerySet, Value, When
+from django.db.models import Case, CharField, Count, F, Prefetch, Q, QuerySet, Value, When
from django.db.models.functions import Coalesce, Now, NullIf
from django.utils import timezone
@@ -2798,6 +2798,9 @@ class ExperimentService:
created_by_display=Coalesce(
NullIf(F("created_by__first_name"), Value("")),
F("created_by__email"),
+ # first_name is a CharField and email an EmailField; Django refuses to
+ # infer a type across the two, so set it explicitly.
+ output_field=CharField(),
)
).order_by(f"{prefix}created_by_display")
else: