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(hogql): match property autocomplete case-insensitively (#126329)

Jovan Sakovic532ccb4e895d
diff --git a/posthog/hogql/autocomplete.py b/posthog/hogql/autocomplete.py
index 4fb6c9f438a7..1043c28ac6cb 100644
--- a/posthog/hogql/autocomplete.py
+++ b/posthog/hogql/autocomplete.py
@@ -1,3 +1,4 @@
+import re
import json
from collections.abc import Callable
from copy import deepcopy
@@ -5,7 +6,9 @@ from enum import Enum, auto
from functools import lru_cache
from typing import Optional, cast
+from django.db.backends.base.base import BaseDatabaseWrapper
from django.db.models import F
+from django.db.models.lookups import Contains
from posthog.schema import (
AutocompleteCompletionItem,
@@ -75,6 +78,13 @@ from common.hogvm.python.stl.bytecode import BYTECODE_STL
ALL_HOG_FUNCTIONS = sorted(list(STL.keys()) + list(BYTECODE_STL.keys()))
MATCH_ANY_CHARACTER = "$$_POSTHOG_ANY_$$"
PROPERTY_DEFINITION_LIMIT = 220
+
+
+class _PostgresILikeContains(Contains):
+ def get_rhs_op(self, connection: BaseDatabaseWrapper, rhs: str) -> str:
+ return f"ILIKE {rhs}"
+
+
# The one path through a Hog function's globals that holds an event's own property bag. Other
# `properties` bags (person, groups, a user-defined input) never carry person property setters.
EVENT_PROPERTIES_GLOBALS_CHAIN = ["event", "properties"]
@@ -787,8 +797,8 @@ def _suggest_property_names(
effective_project_id=effective_project_id_expr(),
group_type_index_key=group_type_index_key_expr(),
).filter(
+ _PostgresILikeContains(F("name"), match_term),
effective_project_id=context.team.project_id, # type: ignore
- name__contains=match_term,
type=property_type,
)
group_type_index_key = _group_type_index_key(table, property_type, joined_group_index)
@@ -963,7 +973,8 @@ def _suggest_table_names(
else:
node_chain_arr = [str(x) for x in node.chain if x != MATCH_ANY_CHARACTER]
node_chain = ".".join(node_chain_arr)
- filtered_table_names = [x.replace(f"{node_chain}.", "") for x in table_names if node_chain in x]
+ node_chain_prefix = re.compile(re.escape(f"{node_chain}."), re.IGNORECASE)
+ filtered_table_names = [node_chain_prefix.sub("", x) for x in table_names if node_chain.lower() in x.lower()]
extend_responses(
keys=filtered_table_names,
diff --git a/posthog/hogql/test/test_autocomplete.py b/posthog/hogql/test/test_autocomplete.py
index c6cc183e7254..9142906de63b 100644
--- a/posthog/hogql/test/test_autocomplete.py
+++ b/posthog/hogql/test/test_autocomplete.py
@@ -281,6 +281,10 @@ class TestAutocomplete(ClickhouseTestMixin, APIBaseTest):
assert len(results.suggestions) == 1
assert results.suggestions[0].label == "some_event_value"
+ query = "select properties.SOME_ from events"
+ results = self._select(query=query, start=18, end=23)
+ assert [s.label for s in results.suggestions] == ["some_event_value"]
+
def test_autocomplete_nested_tables(self):
# Inner table
query = "select event, (select from persons) as blah from events"
@@ -759,6 +763,11 @@ class TestAutocomplete(ClickhouseTestMixin, APIBaseTest):
assert "stripe.some_table" in [x.label for x in results.suggestions]
+ query = "select * from STRIPE."
+ results = self._select(query=query, start=21, end=21)
+
+ assert "some_table" in [x.label for x in results.suggestions]
+
def test_autocomplete_warehouse_table_with_source_and_prefix_dot_notation(self):
credentials = DataWarehouseCredential.objects.create(team=self.team, access_key="key", access_secret="secret")
source = ExternalDataSource.objects.create(