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): route metadata through language service (#100568)

Paweł Szczurb37c5e3e9e7b
diff --git a/posthog/api/services/query.py b/posthog/api/services/query.py
index c11e29fcc0b0..2bd0f4fae29c 100644
--- a/posthog/api/services/query.py
+++ b/posthog/api/services/query.py
@@ -75,7 +75,7 @@ def _language_service_eligible(query: HogQLAutocomplete | HogQLMetadata) -> bool
and query.modifiers is None
)
if isinstance(query, HogQLMetadata):
- return common and query.variables is None and not query.debug and not query.indexUsage
+ return common and query.variables is None and not query.debug
return common
diff --git a/posthog/api/test/test_query_service.py b/posthog/api/test/test_query_service.py
index 2c29affa2e74..ab5bdbf0b39a 100644
--- a/posthog/api/test/test_query_service.py
+++ b/posthog/api/test/test_query_service.py
@@ -34,7 +34,7 @@ from posthog.hogql.direct_connection import INVALID_CONNECTION_ID_ERROR
from posthog.hogql.errors import ResolutionError
from posthog.hogql.language_service import LanguageServiceResult
-from posthog.api.services.query import process_query_model
+from posthog.api.services.query import _language_service_eligible, process_query_model
from posthog.exceptions import DatabaseSchemaUnavailable
from posthog.models import Team, User
@@ -47,6 +47,11 @@ from products.warehouse_sources.backend.facade.types import ExternalDataSourceTy
class TestLanguageServiceRouting(SimpleTestCase):
+ def test_hogql_metadata_with_index_usage_is_language_service_eligible(self) -> None:
+ query = HogQLMetadata(query="SELECT * FROM events", language=HogLanguage.HOG_QL, indexUsage=True)
+
+ assert _language_service_eligible(query)
+
@patch("posthog.api.services.query._language_service_call")
def test_hogql_autocomplete_uses_language_service_response(self, mock_language_service_call: MagicMock):
mock_language_service_call.return_value = LanguageServiceResult(