Skip to content

[DRAFT] fix(typing): graduate sentry.snuba.metrics.query_builder from typing issues list#119032

Draft
cursor[bot] wants to merge 1 commit into
masterfrom
cursor/untyped-module-cleanup-4af7
Draft

[DRAFT] fix(typing): graduate sentry.snuba.metrics.query_builder from typing issues list#119032
cursor[bot] wants to merge 1 commit into
masterfrom
cursor/untyped-module-cleanup-4af7

Conversation

@cursor

@cursor cursor Bot commented Jul 5, 2026

Copy link
Copy Markdown
Contributor

Summary

  • remove sentry.snuba.metrics.query_builder from the tool.mypy.overrides "sentry modules with typing issues" list in pyproject.toml
  • fix typing issues in src/sentry/snuba/metrics/query_builder.py by tightening unions, adding typed narrowing/guards, and normalizing metric params passed into typed metric APIs
  • keep behavior unchanged while making the module pass mypy without the special error-code suppression

Testing

  • python -m tools.mypy_helpers.mypy_without_ignores src/sentry/snuba/metrics/query_builder.py
  • python -m mypy src/sentry/snuba/metrics/query_builder.py
  • prek run -q
  • make test-selective ❌ blocked in this VM (gcloud missing)
  • pytest -n3 -svv --reuse-db tests/sentry/snuba/metrics/test_query_builder.py ❌ blocked in this VM (PostgreSQL/Redis services unavailable; Docker/devservices not available)

@armenzg could you please review this draft PR?

Legal Boilerplate

Look, I get it. The entity doing business as "Sentry" was incorporated in the State of Delaware in 2015 as Functional Software, Inc. and is gonna need some rights from me in order to utilize my contributions in this here PR. So here's the deal: I retain all rights, title and interest in and to my contributions, and by keeping this boilerplate intact I confirm that Sentry can use, modify, copy, and redistribute my contributions, under Sentry's choice of terms.

Open in Web View Automation 

Co-authored-by: Armen Zambrano G. <armenzg@users.noreply.github.com>
@github-actions github-actions Bot added the Scope: Backend Automatically applied to PRs that change backend components label Jul 5, 2026
@github-actions

github-actions Bot commented Jul 5, 2026

Copy link
Copy Markdown
Contributor

Backend Test Failures

Failures on 6379f96 in this run:

tests/sentry/snuba/metrics/test_query_builder.py::test_only_can_filter_operations_can_be_added_to_where[valid filtering by metrics expression]log
[gw0] linux -- Python 3.13.1 /home/runner/work/sentry/sentry/.venv/bin/python3
src/sentry/snuba/metrics/fields/base.py:584: in generate_snql_function
    return self.snql_func(**kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^
E   TypeError: team_key_transaction_snql() missing 1 required positional argument: 'team_key_condition_rhs'

During handling of the above exception, another exception occurred:
tests/sentry/snuba/metrics/test_query_builder.py:1500: in test_only_can_filter_operations_can_be_added_to_where
    ).get_snuba_queries()
      ^^^^^^^^^^^^^^^^^^^
src/sentry/snuba/metrics/query_builder.py:1230: in get_snuba_queries
    where = self._build_where()
            ^^^^^^^^^^^^^^^^^^^
src/sentry/snuba/metrics/query_builder.py:958: in _build_where
    lhs=metric_expression.generate_where_statements(
src/sentry/snuba/metrics/fields/base.py:890: in generate_where_statements
    return self.generate_select_statements(
src/sentry/snuba/metrics/fields/base.py:782: in generate_select_statements
    self.build_conditional_aggregate_for_metric(
src/sentry/snuba/metrics/fields/base.py:850: in build_conditional_aggregate_for_metric
    return self.metric_operation.generate_snql_function(
src/sentry/snuba/metrics/fields/base.py:586: in generate_snql_function
    raise InvalidParams(str(e))
E   sentry.exceptions.InvalidParams: team_key_transaction_snql() missing 1 required positional argument: 'team_key_condition_rhs'
tests/sentry/snuba/metrics/test_metrics_layer/test_metrics_enhanced_performance.py::PerformanceMetricsLayerTestCase::test_team_key_transactions_my_teamslog
[gw1] linux -- Python 3.13.1 /home/runner/work/sentry/sentry/.venv/bin/python3
src/sentry/snuba/metrics/fields/base.py:584: in generate_snql_function
    return self.snql_func(**kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^
E   TypeError: team_key_transaction_snql() missing 1 required positional argument: 'team_key_condition_rhs'

During handling of the above exception, another exception occurred:
tests/sentry/snuba/metrics/test_metrics_layer/test_metrics_enhanced_performance.py:1564: in test_team_key_transactions_my_teams
    data = get_series(
src/sentry/snuba/metrics/datasource.py:755: in get_series
    ).get_snuba_queries()
      ^^^^^^^^^^^^^^^^^^^
src/sentry/snuba/metrics/query_builder.py:1231: in get_snuba_queries
    groupby = self._build_groupby()
              ^^^^^^^^^^^^^^^^^^^^^
src/sentry/snuba/metrics/query_builder.py:1017: in _build_groupby
    self.generate_snql_for_action_by_fields(
src/sentry/snuba/metrics/query_builder.py:910: in generate_snql_for_action_by_fields
    return metric_expression.generate_groupby_statements(
src/sentry/snuba/metrics/fields/base.py:871: in generate_groupby_statements
    return self.generate_select_statements(
src/sentry/snuba/metrics/fields/base.py:782: in generate_select_statements
    self.build_conditional_aggregate_for_metric(
src/sentry/snuba/metrics/fields/base.py:850: in build_conditional_aggregate_for_metric
    return self.metric_operation.generate_snql_function(
src/sentry/snuba/metrics/fields/base.py:586: in generate_snql_function
    raise InvalidParams(str(e))
E   sentry.exceptions.InvalidParams: team_key_transaction_snql() missing 1 required positional argument: 'team_key_condition_rhs'
tests/sentry/snuba/metrics/test_query_builder.py::test_only_can_groupby_operations_can_be_added_to_groupby[valid grouping by metrics expression]log
[gw1] linux -- Python 3.13.1 /home/runner/work/sentry/sentry/.venv/bin/python3
src/sentry/snuba/metrics/fields/base.py:584: in generate_snql_function
    return self.snql_func(**kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^
E   TypeError: team_key_transaction_snql() missing 1 required positional argument: 'team_key_condition_rhs'

During handling of the above exception, another exception occurred:
tests/sentry/snuba/metrics/test_query_builder.py:1401: in test_only_can_groupby_operations_can_be_added_to_groupby
    ).get_snuba_queries()
      ^^^^^^^^^^^^^^^^^^^
src/sentry/snuba/metrics/query_builder.py:1231: in get_snuba_queries
    groupby = self._build_groupby()
              ^^^^^^^^^^^^^^^^^^^^^
src/sentry/snuba/metrics/query_builder.py:1017: in _build_groupby
    self.generate_snql_for_action_by_fields(
src/sentry/snuba/metrics/query_builder.py:910: in generate_snql_for_action_by_fields
    return metric_expression.generate_groupby_statements(
src/sentry/snuba/metrics/fields/base.py:871: in generate_groupby_statements
    return self.generate_select_statements(
src/sentry/snuba/metrics/fields/base.py:782: in generate_select_statements
    self.build_conditional_aggregate_for_metric(
src/sentry/snuba/metrics/fields/base.py:850: in build_conditional_aggregate_for_metric
    return self.metric_operation.generate_snql_function(
src/sentry/snuba/metrics/fields/base.py:586: in generate_snql_function
    raise InvalidParams(str(e))
E   sentry.exceptions.InvalidParams: team_key_transaction_snql() missing 1 required positional argument: 'team_key_condition_rhs'
tests/sentry/snuba/metrics/test_metrics_layer/test_metrics_enhanced_performance.py::PerformanceMetricsLayerTestCase::test_team_key_transaction_as_conditionlog
[gw0] linux -- Python 3.13.1 /home/runner/work/sentry/sentry/.venv/bin/python3
src/sentry/snuba/metrics/fields/base.py:584: in generate_snql_function
    return self.snql_func(**kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^
E   TypeError: team_key_transaction_snql() missing 1 required positional argument: 'team_key_condition_rhs'

During handling of the above exception, another exception occurred:
tests/sentry/snuba/metrics/test_metrics_layer/test_metrics_enhanced_performance.py:1932: in test_team_key_transaction_as_condition
    data = get_series(
src/sentry/snuba/metrics/datasource.py:755: in get_series
    ).get_snuba_queries()
      ^^^^^^^^^^^^^^^^^^^
src/sentry/snuba/metrics/query_builder.py:1230: in get_snuba_queries
    where = self._build_where()
            ^^^^^^^^^^^^^^^^^^^
src/sentry/snuba/metrics/query_builder.py:958: in _build_where
    lhs=metric_expression.generate_where_statements(
src/sentry/snuba/metrics/fields/base.py:890: in generate_where_statements
    return self.generate_select_statements(
src/sentry/snuba/metrics/fields/base.py:782: in generate_select_statements
    self.build_conditional_aggregate_for_metric(
src/sentry/snuba/metrics/fields/base.py:850: in build_conditional_aggregate_for_metric
    return self.metric_operation.generate_snql_function(
src/sentry/snuba/metrics/fields/base.py:586: in generate_snql_function
    raise InvalidParams(str(e))
E   sentry.exceptions.InvalidParams: team_key_transaction_snql() missing 1 required positional argument: 'team_key_condition_rhs'

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Scope: Backend Automatically applied to PRs that change backend components

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant