Repository navigation
Conversation
Rebuild the accepted typing campaign on current master as an annotation-only change. Excludes the campaign evaluator, its policy modules, the campaign log, and owner-owned baseline edits. Behavior changes are carved into separate PRs; this commit preserves runtime behavior, including ReleaseFile.save positional compatibility and the release serializer's existing stats and newGroups output. Fix two refactor regressions: starred group search views keep their createdBy/starred/stars fields, and Seer commit lookups stay keyed by primary key instead of sha. Allow the weaklist guard to accept narrowing a wildcard into named modules, which is how the flags endpoints wildcard graduates.
OpenAPI schema generation raised UnableToProceedError for object-valued mappings and abstract Mapping/Sequence annotations introduced by the typing pass. Resolve object as a generic object and treat Mapping and Sequence like dict and list.
|
🚨 Warning: This pull request contains Frontend and Backend changes! It's discouraged to make changes to Sentry's Frontend and Backend in a single pull request. The Frontend and Backend are not atomically deployed. If the changes are interdependent of each other, they must be separated into two pull requests and be made forward or backwards compatible, such that the Backend or Frontend can be safely deployed independently. Have questions? Please ask in the |
|
getsentry verification found one cross-repo typing contract: |
BasePaginator.build_queryset assigned the reversed ordering to queryset.query.order_b, a typo for order_by, when the queryset was already ordered by the descending key and a previous-page cursor needed ascending order. The assignment was silently dropped, so the previous page was filtered as if ascending but still sorted descending, returning the wrong rows. The ordering is now written to order_by, matching the sibling branch.
Exercise the branch that reverses an explicitly descending queryset for a previous-page cursor. Without the order_by fix, the previous page returns the current row instead of the preceding page.
Postponed annotations hide NotRequired from TypedDict runtime introspection, so ActorSerializerResponse.email was emitted as required and rejected the team-owner examples. Remove the postponed annotations from that module. Resolve object-valued mappings as unconstrained values instead of objects; the examples contain arrays and strings in those maps.
The release archive manifest and artifact index are user-uploaded JSON. Validate that the decoded value is an object before treating it as one, so malformed input fails at the boundary instead of raising AttributeError deeper in the archive reader. Review split: getsentry#129432.
Bring the reviewed behavior changes into the canonical campaign branch so the typing diff reflects the final contracts: release serializer defaults, Teams missing-id failure, blank origin preservation, Jira query preconditions, and the paginator previous-page fix.
The manifest root is validated, but `files` still needs an object shape before it is counted and indexed. Reject non-object values at the archive boundary and cover both malformed shapes. Review split: getsentry#129432.
Reject non-object thresholds, unknown or non-integer maximum keys, and non-string units at write time so the serializer casts are backed by a validated invariant. Review split: getsentry#129434.
Manifest headers come from uploaded archives. Treat any non-string debug-id value as absent instead of passing it into symbolic, and drop the casts that assumed the header value was always a string. Review split: getsentry#129435.
Gate new Any usage in graduated modules and require a `# justification:` comment for casts that read JSON, external responses, metadata, or config. The hook checks staged changes locally; `--base` and `--status` support branch-wide checks and campaign metrics. Run the hook against the stage and add tests for graduated/weaklisted modules, trust-boundary casts, and local casts.
Compare Any tokens against the file's previous revision instead of flagging every modified line that still contains an existing Any. Limit the whole-branch mode to Python files under src/.
Use a validating sourcemap-header helper instead of casting arbitrary header values, and document the remaining provider-response casts with explicit justifications so the campaign gate enforces the boundary.
Annotate the remaining functions in these modules and remove their weaklist entries. Full mypy passes with the stricter config, so these modules are now enforced rather than merely annotated.
getsentry deployments extend the admin broadcast response with plans, roles, trial status, region, platform, product, early-adopter, and organization filters. Model them as optional fields on the shared response so getsentry code stays type-compatible without a companion change.
|
Superseded by #129447, which combines this PR and its stacked counterpart into a single branch. |
All modules covered by the mypy
disallow_untyped_defsweaklist now pass strict mypy, so this branch removes the weaklist and the remainingdisable_error_codeallowlist.Result
Success: no issues found in 8460 source filessrc/files; 1,186 strict-checked, 0 still weaklisted# type: ignore(4 moved, 5 removed)check_typing_campaign --goalexits 0;--statusreports 0 weaklist entriescheck_stronglistpassesVerification
SENTRY_LOG_LEVEL=WARNING .venv/bin/python -m mypy --warn-unused-configs→ no issues.venv/bin/python -m tools.mypy_helpers.check_stronglist pyproject.toml→ pass.venv/bin/python -m tools.mypy_helpers.check_typing_campaign --base origin/master→ passmake test-api-docs→ 143 passed, including example validationprek run -q→ passe7cba434a78: backend typing, all 30 backend test shards, api docs, and pre-commit lint passbackend typingrun → failure: 68 errors in 31 files against this branch (master baseline: 4)getsentry follow-up
The generic
Bounded*Fieldcontracts require nullable declarations to name an optional get type, e.g.BoundedBigIntegerField[int | None, int | None](null=True). Sentry is updated, but getsentry still has 39 unparameterized nullable bounded fields; downstream narrowing accounts for most of the remaining errors. A companion getsentry change is required before that downstream job can be green; the sentry-side dispatch check itself is green.Contracts worth reviewing
Event.groupremainsGroup | None; callers and tests narrow with assertions.BoundedIntegerField,CharField, andUUIDFieldare generic over set/get types; non-null defaults stay non-optional.snuba.queryoverloads distinguish thetotals=Truetuple from the scalar result.WrappingU32IntegerFieldjoins the other generic fields; nullable file and blob sizes now declare optional get types, and download responses keep their existing header behavior.snuba.queryresult keys arestr | intbecause grouped columns keep their runtime type; tagstore narrows tag keys to strings at its boundary.RuleCallbackis a named-parameter protocol, so rule futures accept keywordfutures.TypedDictoverrides; monitor audit writes use explicit calls.IntegrationIssueConfigFieldkeepsAnyonly for arbitrary JSON form defaults and choices so the OpenAPI schema stays resolvable; client key choices are emitted as arrays.Tooling
check_stronglistaccepts a pyproject with no weaklist or allowlist.check_typing_campaignchecks a whole-branch diff against the base revision's weaklist, while--status/--goaluse the working tree.Integrated behavior fixes
query.order_btypo for previous-page pagination, with a regression test that fails on the typo and passes with the fixAdminTargetedBroadcastSerializerResponsefor the getsentry targeted broadcast serializerOpenAPI
make test-api-docspasses locally, including example validation. Schema generation needed fixes for arbitrary-JSON integration form fields, client key choices (now rendered as arrays), nullable environment facet names, and nullable release file sizes. The optional prod-vs-dev schema diff still reports annotation-driven changes; review that separately.Note: the green Type Coverage Diff check measures TypeScript, not Python, and does not substantiate this PR.
Companion
The downstream getsentry fixes are in getsentry/getsentry#22868: it parameterizes the remaining nullable bounded fields and aligns the affected billing, audit, export, and Vercel contracts. It reports only the four pre-existing getsentry baseline errors against this branch.
Phase two
The strict-typing ratchet stacked on this branch is #129444. It records the remaining
mypy --stricterrors, enforces that changed files cannot add more, and removes the first batch of inferred-Anycall sites.Remaining red checks
migration driftcompares the squashed migration state against the database. It reports the raw-SQL indexes from1234_grouprelease_new_release_id_indexesmissing from state, which is pre-existing on master; this branch contains no migration changes.(Optional) Shows the difference between the prod and dev schemais expected to differ due to annotation-driven schema changes; review it separately.Shipping
This PR merges first. #129444 and getsentry/getsentry#22868 are stacked on it.
masteras usual.Do not merge #129444 before this one: that PR turns on
strict = truerepo-wide, which only holds once the modules cleaned up here have landed.