Skip to content

[DRAFT] mypy: remove sentry.snuba.metrics.query_builder from typing issues list - #121607

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

[DRAFT] mypy: remove sentry.snuba.metrics.query_builder from typing issues list#121607
cursor[bot] wants to merge 1 commit into
masterfrom
cursor/untyped-module-cleanup-1fab

Conversation

@cursor

@cursor cursor Bot commented Aug 10, 2026

Copy link
Copy Markdown
Contributor

Summary

  • Remove sentry.snuba.metrics.query_builder from the "sentry modules with typing issues" mypy override list in pyproject.toml.
  • Fix all typing issues in src/sentry/snuba/metrics/query_builder.py by adding explicit type narrowing/casts and guards for optional/union fields.
  • Keep runtime behavior intact while satisfying stricter module-level type checking.

Testing

  • export PATH="/workspace/.venv/bin:$HOME/.local/bin:$PATH" && .venv/bin/python -m tools.mypy_helpers.mypy_without_ignores src/sentry/snuba/metrics/query_builder.py
  • .venv/bin/prek run -q
  • ⚠️ .venv/bin/pytest -n3 -svv --reuse-db tests/sentry/test_mypy_stronglist.py is blocked in this VM due unavailable Redis/Docker services.
  • ✅ Fallback verification equivalent to the stronglist assertion: .venv/bin/python -uSm tools.mypy_helpers.check_stronglist pyproject.toml

@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 

@github-actions github-actions Bot added the Scope: Backend Automatically applied to PRs that change backend components label Aug 10, 2026
@getsantry

getsantry Bot commented Sep 1, 2026

Copy link
Copy Markdown
Contributor

This pull request has gone three weeks without activity. In another week, I will close it.

But! If you comment or otherwise update it, I will reset the clock, and if you add the label WIP, I will leave it alone unless WIP is removed ... forever!


"A weed is but an unloved flower." ― Ella Wheeler Wilcox 🥀

@getsantry getsantry Bot added the Stale label Sep 1, 2026
@github-actions

github-actions Bot commented Sep 1, 2026

Copy link
Copy Markdown
Contributor

Backend Test Failures

Failures on ce4876f in this run:

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:1516: in test_only_can_filter_operations_can_be_added_to_where
    ).get_snuba_queries()
      ^^^^^^^^^^^^^^^^^^^
src/sentry/snuba/metrics/query_builder.py:1225: in get_snuba_queries
    where = self._build_where()
            ^^^^^^^^^^^^^^^^^^^
src/sentry/snuba/metrics/query_builder.py:950: in _build_where
    raise InvalidParams(f"Cannot resolve {condition.lhs} into SnQL")
E   sentry.exceptions.InvalidParams: Cannot resolve session.errored into SnQL

During handling of the above exception, another exception occurred:
tests/sentry/snuba/metrics/test_query_builder.py:1513: 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: 'Cannot resolve session.errored into SnQL'

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 Stale

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant