Skip to content

Draft: remove query_builder from mypy typing-issues list - #119401

Draft
cursor[bot] wants to merge 2 commits into
masterfrom
cursor/untyped-module-cleanup-503f
Draft

Draft: remove query_builder from mypy typing-issues list#119401
cursor[bot] wants to merge 2 commits into
masterfrom
cursor/untyped-module-cleanup-503f

Conversation

@cursor

@cursor cursor Bot commented Jul 10, 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 all newly-exposed mypy errors in src/sentry/snuba/metrics/query_builder.py by tightening/aligning type annotations and narrowing logic around metric/groupby/orderby handling.
  • Keep behavior the same while making type expectations explicit (operation typing, param casting, metric field assertions, discover interval validation, and component-entity mapping typing).

Validation

  • .venv/bin/python -m mypy src/sentry/snuba/metrics/query_builder.py
  • .venv/bin/prek run -q
  • ⚠️ make test-selective could not run in this environment because gcloud is not installed.
  • ⚠️ SENTRY_SKIP_SERVICE_VALIDATION=1 .venv/bin/pytest -n3 -svv --reuse-db tests/sentry/snuba/metrics/test_query_builder.py fails due missing local Redis (ConnectionRefusedError: localhost:6379).

@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 

cursoragent and others added 2 commits July 10, 2026 12:05
Co-authored-by: Armen Zambrano G. <armenzg@users.noreply.github.com>
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 10, 2026
@github-actions

github-actions Bot commented Jul 10, 2026

Copy link
Copy Markdown
Contributor

Backend Test Failures

Failures on af1a87d in this run:

tests/sentry/snuba/metrics/test_query_builder.py::test_only_can_filter_operations_can_be_added_to_where[invalid filtering by derived metric - release_health]log
[gw0] linux -- Python 3.13.1 /home/runner/work/sentry/sentry/.venv/bin/python3
tests/sentry/snuba/metrics/test_query_builder.py:1496: in test_only_can_filter_operations_can_be_added_to_where
    ).get_snuba_queries()
      ^^^^^^^^^^^^^^^^^^^
src/sentry/snuba/metrics/query_builder.py:1210: in get_snuba_queries
    where = self._build_where()
            ^^^^^^^^^^^^^^^^^^^
src/sentry/snuba/metrics/query_builder.py:941: in _build_where
    raise InvalidParams(f"Unsupported condition field: {condition.lhs}")
E   sentry.exceptions.InvalidParams: Unsupported condition field: transaction.failure_rate

During handling of the above exception, another exception occurred:
tests/sentry/snuba/metrics/test_query_builder.py:1493: in test_only_can_filter_operations_can_be_added_to_where
    with pytest.raises(InvalidParams, match=error_string):
         ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
E   AssertionError: Regex pattern did not match.
E     Expected regex: 'Cannot filter by metric transaction.failure_rate'
E     Actual message: 'Unsupported condition field: transaction.failure_rate'
tests/sentry/snuba/metrics/test_query_builder.py::test_only_can_filter_operations_can_be_added_to_where[invalid filtering by composite entity derived metric - release_health]log
[gw1] linux -- Python 3.13.1 /home/runner/work/sentry/sentry/.venv/bin/python3
tests/sentry/snuba/metrics/test_query_builder.py:1496: in test_only_can_filter_operations_can_be_added_to_where
    ).get_snuba_queries()
      ^^^^^^^^^^^^^^^^^^^
src/sentry/snuba/metrics/query_builder.py:1210: in get_snuba_queries
    where = self._build_where()
            ^^^^^^^^^^^^^^^^^^^
src/sentry/snuba/metrics/query_builder.py:941: in _build_where
    raise InvalidParams(f"Unsupported condition field: {condition.lhs}")
E   sentry.exceptions.InvalidParams: Unsupported condition field: session.errored

During handling of the above exception, another exception occurred:
tests/sentry/snuba/metrics/test_query_builder.py:1493: in test_only_can_filter_operations_can_be_added_to_where
    with pytest.raises(InvalidParams, match=error_string):
         ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
E   AssertionError: Regex pattern did not match.
E     Expected regex: 'Cannot filter by metric session.errored'
E     Actual message: 'Unsupported condition field: session.errored'

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