Skip to content

fix(typing): Replace type: ignore comments with proper type fixes#107721

Closed
JoshFerge wants to merge 1 commit into
jferg/upgrade-mypy-upstream-django-stubsfrom
jferg/fix-type-ignores-mypy-upgrade
Closed

fix(typing): Replace type: ignore comments with proper type fixes#107721
JoshFerge wants to merge 1 commit into
jferg/upgrade-mypy-upstream-django-stubsfrom
jferg/fix-type-ignores-mypy-upgrade

Conversation

@JoshFerge

Copy link
Copy Markdown
Member

Summary

Stacked on #107710. Fixes the # type: ignore comments that were added during the mypy 1.19.1 upgrade by replacing them with proper type-safe solutions.

Changes by category

attr-defined fixes (relay, organization, user_from_signed_request):

  • Created get_relay_from_request() and get_relay_request_data() typed helpers in authentication.py
  • Updated all relay endpoint files to use the new helpers instead of request.relay / request.relay_request_data
  • Used getattr() for request.organization access (returns Any, satisfies mypy)
  • Used existing is_user_signed_request() helper for user_from_signed_request

misc fixes (ORM lookups with possibly-None values):

  • Added explicit None checks before ORM .get(id=...) calls where the ID could be None
  • Used assert ... is not None for authenticated user IDs and organization IDs
  • Extracted request.GET.get("id") into a variable to help mypy narrow the type
  • Changed filter(project=project) to filter(project_id=project.id) for HybridCloudForeignKey

arg-type fix (base_query_set.py):

  • Added isinstance(col, str) check before dict lookup, properly narrowing str | Combinable

unreachable fix (delayed_processing.py):

  • Changed instance_data.get("event_id") to instance_data["event_id"] since event_id is a required key in the EventData TypedDict — the None check was correctly flagged as unreachable

Other fixes:

  • Removed invalid select_related() on a ManyToManyField (uptime subscriptions)
  • Used cast() for Django _meta.get_field() return type in test fixture
  • Kept # type: ignore[no-redef] for annotation shadowing model field (genuine mypy limitation)

Remaining type: ignore

One # type: ignore[no-redef] remains in workflow_group_history_serializer.py — this is a known mypy limitation where .annotate(detector_id=...) shadows an existing model field name.

Test plan

  • mypy passes on all 21 changed files with 0 errors
  • All pre-commit hooks pass
  • CI passes

- Create get_relay_from_request() and get_relay_request_data() helpers
  in authentication.py for typed relay attribute access
- Use getattr() for dynamic request.organization access
- Use is_user_signed_request() for user_from_signed_request checks
- Add None guards before ORM lookups with possibly-None values
- Fix isinstance check for str keys in base_query_set order_by
- Remove unreachable code path (EventData.event_id is required)
- Remove invalid select_related on ManyToManyField
- Use cast() for Django _meta.get_field() return type
@github-actions github-actions Bot added the Scope: Backend Automatically applied to PRs that change backend components label Feb 5, 2026
@JoshFerge JoshFerge closed this Feb 5, 2026
@JoshFerge JoshFerge deleted the jferg/fix-type-ignores-mypy-upgrade branch February 5, 2026 22:11
@github-actions github-actions Bot locked and limited conversation to collaborators Feb 21, 2026
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

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