diff --git a/frontend/__snapshots__/scenes-app-insights--trends-line--light--webkit.png b/frontend/__snapshots__/scenes-app-insights--trends-line--light--webkit.png index e6507b0269eff..d60cbfa5e7556 100644 Binary files a/frontend/__snapshots__/scenes-app-insights--trends-line--light--webkit.png and b/frontend/__snapshots__/scenes-app-insights--trends-line--light--webkit.png differ diff --git a/frontend/src/queries/nodes/HogQLQuery/HogQLQueryEditor.tsx b/frontend/src/queries/nodes/HogQLQuery/HogQLQueryEditor.tsx index 30df1eb1c3424..45cb608451271 100644 --- a/frontend/src/queries/nodes/HogQLQuery/HogQLQueryEditor.tsx +++ b/frontend/src/queries/nodes/HogQLQuery/HogQLQueryEditor.tsx @@ -205,10 +205,6 @@ export function HogQLQueryEditor(props: HogQLQueryEditorProps): JSX.Element { monaco.languages.registerCompletionItemProvider('mysql', { triggerCharacters: [' ', ',', '.'], provideCompletionItems: async (model, position) => { - if (!logic.isMounted()) { - return undefined - } - if (!featureFlags[FEATURE_FLAGS.HOGQL_AUTOCOMPLETE]) { return undefined } @@ -226,7 +222,7 @@ export function HogQLQueryEditor(props: HogQLQueryEditorProps): JSX.Element { const response = await query({ kind: NodeKind.HogQLAutocomplete, - select: logic.values.queryInput, + select: model.getValue(), // Use the text from the model instead of logic due to a race condition on the logic values updating quick enough filters: props.query.filters, startPosition: startOffset, endPosition: endOffset, diff --git a/posthog/hogql/autocomplete.py b/posthog/hogql/autocomplete.py index c1152a1a60cab..3a86ecd3fc3ae 100644 --- a/posthog/hogql/autocomplete.py +++ b/posthog/hogql/autocomplete.py @@ -354,7 +354,10 @@ def get_hogql_autocomplete(query: HogQLAutocomplete, team: Team) -> HogQLAutocom aliased_table = tables.get(str(chain_part)) if aliased_table is not None: last_table = aliased_table - continue + continue + else: + # Dont continue if the alias is not found in the query + break # Ignore last chain part, it's likely an incomplete word or added characters is_last_part = index >= (chain_len - 2) @@ -384,18 +387,21 @@ def get_hogql_autocomplete(query: HogQLAutocomplete, team: Team) -> HogQLAutocom if match_term == MATCH_ANY_CHARACTER: match_term = "" - properties = PropertyDefinition.objects.filter( + property_query = PropertyDefinition.objects.filter( name__contains=match_term, team_id=team.pk, type=property_type, - )[:PROPERTY_DEFINITION_LIMIT].values("name", "property_type") + ) + + total_property_count = property_query.count() + properties = property_query[:PROPERTY_DEFINITION_LIMIT].values("name", "property_type") extend_responses( keys=[prop["name"] for prop in properties], suggestions=response.suggestions, details=[prop["property_type"] for prop in properties], ) - response.incomplete_list = True + response.incomplete_list = total_property_count > PROPERTY_DEFINITION_LIMIT elif isinstance(field, VirtualTable) or isinstance(field, LazyTable): fields = list(last_table.fields.items()) extend_responses( diff --git a/posthog/hogql/test/test_autocomplete.py b/posthog/hogql/test/test_autocomplete.py index 0f5ac0a464129..46eb8a1cd0394 100644 --- a/posthog/hogql/test/test_autocomplete.py +++ b/posthog/hogql/test/test_autocomplete.py @@ -165,7 +165,28 @@ def test_autocomplete_complete_list(self): results = self._query_response(query=query, start=7, end=12) assert results.incomplete_list is False - def test_autocomplete_incomplete_list(self): + def test_autocomplete_properties_list_with_under_220_properties(self): + for index in range(20): + PropertyDefinition.objects.create( + team=self.team, + name=f"some_event_value_{index}", + property_type="String", + type=PropertyDefinition.Type.EVENT, + ) + + query = "select properties. from events" + results = self._query_response(query=query, start=18, end=18) + assert results.incomplete_list is False + + def test_autocomplete_properties_list_with_over_220_properties(self): + for index in range(221): + PropertyDefinition.objects.create( + team=self.team, + name=f"some_event_value_{index}", + property_type="String", + type=PropertyDefinition.Type.EVENT, + ) + query = "select properties. from events" results = self._query_response(query=query, start=18, end=18) assert results.incomplete_list is True @@ -199,3 +220,9 @@ def test_autocomplete_joined_tables_aliases(self): assert len(results.suggestions) == 2 assert results.suggestions[0].label == "e" assert results.suggestions[1].label == "p" + + def test_autocomplete_non_existing_alias(self): + query = "select o. from events e" + results = self._query_response(query=query, start=9, end=9) + + assert len(results.suggestions) == 0