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

typing(search): Add parent class for ErrorsQueryBuilder #78213

Closed
wants to merge 1 commit into from
Closed
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
1 change: 0 additions & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -319,7 +319,6 @@ module = [
"sentry.scim.endpoints.members",
"sentry.scim.endpoints.teams",
"sentry.scim.endpoints.utils",
"sentry.search.events.builder.errors",
"sentry.search.events.builder.metrics",
"sentry.search.events.datasets.discover",
"sentry.search.events.datasets.filter_aliases",
Expand Down
3 changes: 2 additions & 1 deletion src/sentry/search/events/builder/errors.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
)

from sentry.api.issue_search import convert_query_values, convert_status_value
from sentry.search.events.builder.base import BaseQueryBuilder
from sentry.search.events.builder.discover import (
DiscoverQueryBuilder,
TimeseriesQueryBuilder,
Expand All @@ -30,7 +31,7 @@
value_converters = {"status": convert_status_value}


class ErrorsQueryBuilderMixin:
class ErrorsQueryBuilderMixin(BaseQueryBuilder):
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The missing parameters are set here:

def __init__(
self,
dataset: Dataset,
params: ParamsType,
config: QueryBuilderConfig | None = None,
snuba_params: SnubaParams | None = None,
query: str | None = None,
selected_columns: list[str] | None = None,
groupby_columns: list[str] | None = None,
equations: list[str] | None = None,
orderby: list[str] | str | None = None,
limit: int | None = 50,
offset: int | None = 0,
limitby: tuple[str, int] | None = None,
turbo: bool = False,
sample_rate: float | None = None,
array_join: str | None = None,
entity: Entity | None = None,
):
if config is None:
self.builder_config = QueryBuilderConfig()
else:
self.builder_config = config
if self.builder_config.parser_config_overrides is None:
self.builder_config.parser_config_overrides = {}
self.dataset = dataset
# filter params is the older style params, shouldn't be used anymore
self.filter_params = params
if snuba_params is not None:
self.filter_params = snuba_params.filter_params
self.params = self._dataclass_params(snuba_params, params)
org_id = self.params.organization_id
self.organization_id: int | None = (
org_id if org_id is not None and isinstance(org_id, int) else None
)
self.raw_equations = equations
self.raw_orderby = orderby
self.query = query
self.selected_columns = selected_columns
self.groupby_columns = groupby_columns
self.tips: dict[str, set[str]] = {
"query": set(),
"columns": set(),
}
# Base Tenant IDs for any Snuba Request built/executed using a QueryBuilder
org_id = self.organization_id or (
self.params.organization.id if self.params.organization else None
)
self.tenant_ids: dict[str, str | None | int] | None = dict()
if org_id is not None:
self.tenant_ids["organization_id"] = org_id
if "use_case_id" in params and params.get("use_case_id") is not None:
self.tenant_ids["use_case_id"] = params.get("use_case_id")
if not self.tenant_ids:
self.tenant_ids = None
# Function is a subclass of CurriedFunction
self.where: list[WhereType] = []
self.having: list[WhereType] = []
# The list of aggregates to be selected
self.aggregates: list[CurriedFunction] = []
self.columns: list[SelectType] = []
self.orderby: list[OrderBy] = []
self.groupby: list[SelectType] = []
self.projects_to_filter: set[int] = set()
self.function_alias_map: dict[str, fields.FunctionDetails] = {}
self.equation_alias_map: dict[str, SelectType] = {}
# field: function map for post-processing values
self.value_resolver_map: dict[str, Callable[[Any], Any]] = {}
# value_resolver_map may change type
self.meta_resolver_map: dict[str, str] = {}
# These maps let us convert from prefixed to original tag keys
# and vice versa to avoid collisions where tags and functions have
# similar aliases
self.prefixed_to_tag_map: dict[str, str] = {}
self.tag_to_prefixed_map: dict[str, str] = {}
# Tags with their type in them can't be passed to clickhouse because of the space
# This map is so we can convert those back before the user sees the internal alias
self.typed_tag_to_alias_map: dict[str, str] = {}
self.alias_to_typed_tag_map: dict[str, str] = {}
self.requires_other_aggregates = False
self.limit = self.resolve_limit(limit)
self.offset = None if offset is None else Offset(offset)
self.turbo = turbo
self.sample_rate = sample_rate
self.config = self.load_config()
self.parse_config()
self.start: datetime | None = None
self.end: datetime | None = None
self.resolve_query(
query=query,
selected_columns=selected_columns,
groupby_columns=groupby_columns,
equations=equations,
orderby=orderby,
)
self.entity = entity
self.limitby = self.resolve_limitby(limitby)
self.array_join = None if array_join is None else [self.resolve_column(array_join)]

mypy src/sentry/search/events/builder/errors.py
src/sentry/search/events/builder/errors.py:40: error: "parse_query" undefined in superclass  [misc]
src/sentry/search/events/builder/errors.py:43: error: "ErrorsQueryBuilderMixin" has no attribute "params"  [attr-defined]
src/sentry/search/events/builder/errors.py:44: error: "ErrorsQueryBuilderMixin" has no attribute "params"  [attr-defined]
src/sentry/search/events/builder/errors.py:45: error: "ErrorsQueryBuilderMixin" has no attribute "params"  [attr-defined]
src/sentry/search/events/builder/errors.py:52: error: "ErrorsQueryBuilderMixin" has no attribute "dataset"  [attr-defined]
src/sentry/search/events/builder/errors.py:52: error: "ErrorsQueryBuilderMixin" has no attribute "sample_rate"  [attr-defined]
src/sentry/search/events/builder/errors.py:62: error: "resolve_params" undefined in superclass  [misc]
src/sentry/search/events/builder/errors.py:68: error: "ErrorsQueryBuilderMixin" has no attribute "params"  [attr-defined]
src/sentry/search/events/builder/errors.py:81: error: "resolve_query" undefined in superclass  [misc]
src/sentry/search/events/builder/errors.py:85: error: "aliased_column" undefined in superclass  [misc]
src/sentry/search/events/builder/errors.py:100: error: "ErrorsQueryBuilderMixin" has no attribute "resolve_column_name"  [attr-defined]
src/sentry/search/events/builder/errors.py:108: error: "ErrorsQueryBuilderMixin" has no attribute "dataset"  [attr-defined]
Found 12 errors in 1 file (checked 1 source file)

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

mixins in general aren't typesafe -- this should probably be refactored to composition or otherwise

def __init__(self, *args, **kwargs):
self.match = None
self.entities = set()
Expand Down
Loading