Skip to content

Conversation

Christinarlong
Copy link
Contributor

No description provided.

@github-actions github-actions bot added the Scope: Backend Automatically applied to PRs that change backend components label Aug 20, 2025
@Christinarlong Christinarlong marked this pull request as ready for review August 20, 2025 21:16
@Christinarlong Christinarlong requested review from a team as code owners August 20, 2025 21:16
field.widget.choices = choices


def get_field_choices(field: forms.Field) -> Any:
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks anthony for the workaround 🙏

The Any here isn't ideal but the alternative would be grabbing _ types from django-stubs (which I didn't see as an existing pattern?) and this is a workaround anyway.

service_id = _validate_int_field("service", cleaned_data)

if service_id:
if service_id and integration_id:
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a bit of a logical change, but the current logic would error anyway if there wasn't an integration_id given 🤷‍♀️

Copy link

codecov bot commented Aug 20, 2025

Codecov Report

❌ Patch coverage is 97.56098% with 1 line in your changes missing coverage. Please review.
✅ All tests successful. No failed tests found.

Files with missing lines Patch % Lines
src/sentry/integrations/pagerduty/actions/form.py 75.00% 1 Missing ⚠️
Additional details and impacted files
@@                  Coverage Diff                  @@
##             hackweek/typing-25   #98075   +/-   ##
=====================================================
  Coverage                      ?   80.59%           
=====================================================
  Files                         ?     8598           
  Lines                         ?   378518           
  Branches                      ?    24710           
=====================================================
  Hits                          ?   305078           
  Misses                        ?    73062           
  Partials                      ?      378           

Copy link
Member

@isabellaenriquez isabellaenriquez left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lgtm, just one question!


self.fields["account"].choices = integrations
self.fields["account"].widget.choices = self.fields["account"].choices
set_field_choices(self.fields["account"], integrations)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

what was the reason these changes were needed?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yeah they're needed because mypy doesn't see .choices as an accessible attr on ChoiceField after initialization see typeddjango/django-stubs#1858 & typeddjango/django-stubs#1514.

@Christinarlong Christinarlong changed the base branch from master to hackweek/typing-25 August 20, 2025 22:23
Comment on lines 51 to 52
"account": dict(get_field_choices(self.fields["account"])).get(integration_id),
"service": dict(get_field_choices(self.fields["service"])).get(service_id),
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

rather than introduce get_field_choices (sorta abusing choices as a data smuggling mechanism) I would recommend doing it like I did here: 865de37

@Christinarlong Christinarlong merged commit 606793e into hackweek/typing-25 Aug 21, 2025
90 of 93 checks passed
@Christinarlong Christinarlong deleted the crl/type-pagerduty branch August 21, 2025 19:41
@github-actions github-actions bot locked and limited conversation to collaborators Sep 6, 2025
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.

3 participants