Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ref(on-demand): Improve query builder integration #54446

Merged
merged 9 commits into from
Aug 10, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/sentry/incidents/serializers/alert_rule.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
from django.db import router, transaction
from django.utils import timezone
from rest_framework import serializers
from snuba_sdk import Column, Condition, Function, Limit, Op
from snuba_sdk import Column, Condition, Limit, Op

from sentry import features
from sentry.api.fields.actor import ActorField
Expand Down Expand Up @@ -303,7 +303,7 @@ def _validate_snql_query(self, data, entity_subscription, projects):
except (InvalidSearchQuery, ValueError) as e:
raise serializers.ValidationError(f"Invalid Query or Metric: {e}")

if not isinstance(query_builder.columns[0], Function):
if not query_builder.are_columns_resolved():
raise serializers.ValidationError(
"Invalid Metric: Please pass a valid function for aggregation"
)
Expand Down
5 changes: 5 additions & 0 deletions src/sentry/search/events/builder/discover.py
Original file line number Diff line number Diff line change
Expand Up @@ -241,6 +241,7 @@ def __init__(
self.on_demand_metrics_enabled = on_demand_metrics_enabled
self.auto_fields = auto_fields
self.query = query
self.selected_columns = selected_columns
self.groupby_columns = groupby_columns
self.functions_acl = set() if functions_acl is None else functions_acl
self.equation_config = {} if equation_config is None else equation_config
Expand Down Expand Up @@ -309,12 +310,16 @@ def __init__(
orderby=orderby,
)

def are_columns_resolved(self) -> bool:
return self.columns and isinstance(self.columns[0], Function)

def get_default_converter(self) -> Callable[[event_search.SearchFilter], Optional[WhereType]]:
return self._default_filter_converter

def resolve_time_conditions(self) -> None:
if self.skip_time_conditions:
return

# start/end are required so that we can run a query in a reasonable amount of time
if self.params.start is None or self.params.end is None:
raise InvalidSearchQuery("Cannot query without a valid date range")
Expand Down
Loading
Loading