Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore(github): fix typing for github client #75480

Closed
wants to merge 4 commits into from

Conversation

cathteng
Copy link
Member

@cathteng cathteng commented Aug 1, 2024

bufo-dont-even-see-the-code-anymore

@github-actions github-actions bot added the Scope: Backend Automatically applied to PRs that change backend components label Aug 1, 2024
Copy link

sentry-io bot commented Aug 1, 2024

🔍 Existing Issues For Review

Your pull request is modifying functions with the following pre-existing issues:

📄 File: src/sentry/shared_integrations/client/base.py

Function Unhandled Issue
_request ApiUnauthorized: {"message":"Could not authenticate","took":0.0,"requestId":"b46ffcb1-2538-45cf-adc8-f009c40d37d6"} ...
Event Count: 1

Did you find this useful? React with a 👍 or 👎

Copy link

codecov bot commented Aug 1, 2024

Codecov Report

Attention: Patch coverage is 69.35484% with 19 lines in your changes missing coverage. Please review.

Project coverage is 78.19%. Comparing base (77c048a) to head (5f20888).
Report is 1080 commits behind head on master.

Files with missing lines Patch % Lines
src/sentry/integrations/github/client.py 71.15% 8 Missing and 7 partials ⚠️
src/sentry/tasks/integrations/github/utils.py 0.00% 1 Missing and 1 partial ⚠️
src/sentry/integrations/github/search.py 50.00% 0 Missing and 1 partial ⚠️
src/sentry/integrations/github/utils.py 80.00% 0 Missing and 1 partial ⚠️
Additional details and impacted files
@@           Coverage Diff            @@
##           master   #75480    +/-   ##
========================================
  Coverage   78.18%   78.19%            
========================================
  Files        6809     6816     +7     
  Lines      302915   303040   +125     
  Branches    52132    52159    +27     
========================================
+ Hits       236844   236958   +114     
+ Misses      59686    59684     -2     
- Partials     6385     6398    +13     
Files with missing lines Coverage Δ
src/sentry/integrations/github/blame.py 90.24% <100.00%> (-0.16%) ⬇️
src/sentry/integrations/github/search.py 94.23% <50.00%> (-1.85%) ⬇️
src/sentry/integrations/github/utils.py 90.90% <80.00%> (-2.43%) ⬇️
src/sentry/tasks/integrations/github/utils.py 95.55% <0.00%> (-4.45%) ⬇️
src/sentry/integrations/github/client.py 81.44% <71.15%> (-1.99%) ⬇️

... and 38 files with indirect coverage changes

@cathteng cathteng marked this pull request as ready for review August 1, 2024 22:20
@cathteng cathteng requested review from a team as code owners August 1, 2024 22:20
@cathteng cathteng requested review from a team August 1, 2024 22:20
Comment on lines 48 to 51
self.limit = info.get("limit")
self.remaining = info.get("remaining", 0)
self.reset = info.get("reset")
self.used = info.get("used")
Copy link
Member

Choose a reason for hiding this comment

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

would rather not weaken these -- the brackets are preferrable since we know the structure (whereas .get would allow a programming error to slip through unnoticed on a typo)

Comment on lines 305 to 306
if resp.status_code == 204:
return {}
return BaseApiResponse(status_code=204)
Copy link
Member

Choose a reason for hiding this comment

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

I've been meaning to make this change for a while -- but it's not so simple

some things test if not response: ... and assume that's a 204 so it needs quite a lot of work to safely unwind this (probably needs some sort of opt-in dont_special_case_204s=True which can then be targetted with @overload and not return the empty dict here -- but it's quite a bit of work!)

this probably needs some more involved tracing to nuke properly

also callers really shouldn't need BaseApiResponseX since it should be one of the two types specifically (based on the raw_response=...) -- so I suspect the github client doesn't need this union either and will always get specifically one or the other response type

Copy link
Member Author

Choose a reason for hiding this comment

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

i see... i put the {} back then. is it possible to define __bool__ to determine if an object is truthy? for 204s we could return False

Copy link
Member

@asottile-sentry asottile-sentry left a comment

Choose a reason for hiding this comment

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

I'm a little torn because I think this is an improvement -- but I also think that the whole api client stuff needs to be torn out and rethought (like I think ideally there would be some response schemas with typeddicts for the structure -- and not have to guess whether it's a requests.Response, the weird dict subclass, or empty dict from 204s)

it'd be a larger chunk of work but it would make everything way easier to work with and have actual proper types

Comment on lines 60 to +61
class GithubProxyClient(IntegrationProxyClient):
integration: RpcIntegration | Integration
Copy link
Member

Choose a reason for hiding this comment

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

I think this is due to it being expected from a subclass -- but it turns out there's only one subclass! so let's merge GithubProxyClient and the class below and then I think this annotation may be able to be removed?

super().__init__(
org_integration_id=org_integration_id,
verify_ssl=verify_ssl,
logging_context=logging_context,
**kwargs,
integration_id=getattr(self.integration, "id", None),
Copy link
Member

Choose a reason for hiding this comment

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

this getattr shouldn't be necessary if the integration: Integration type is correct -- since that always has an id: int

@getsantry
Copy link
Contributor

getsantry bot commented Aug 24, 2024

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 Aug 24, 2024
@armenzg armenzg removed the request for review from a team August 28, 2024 18:40
@getsantry getsantry bot closed this Sep 5, 2024
@github-actions github-actions bot locked and limited conversation to collaborators Sep 20, 2024
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 Stale
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants