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

Update user agent for NetworkClient() #11001

Merged
merged 5 commits into from
Jul 27, 2023

Conversation

mhasbini
Copy link
Contributor

@mhasbini mhasbini commented Jul 21, 2023

Summary

Update user agent for NetworkClient() to include the project name with its current version.

I need guidance in deciding how to implement this change for files that includes requests directly. I have two approaches:

  • Refactor these imports to use NetworkClient()
  • If the above is not recommended for certain reasons then create a new factory for requests that have this custom user agent.

lmk what's the recommended approach.

References

Fixes #10995

Reviewer guidance

  • should be handled by the automated test

Testing checklist

  • Contributor has fully tested the PR manually
  • If there are any front-end changes, before/after screenshots are included
  • Critical user journeys are covered by Gherkin stories
  • Critical and brittle code paths are covered by unit tests

PR process

  • PR has the correct target branch and milestone
  • PR has 'needs review' or 'work-in-progress' label
  • If PR is ready for review, a reviewer has been added. (Don't use 'Assignees')
  • If this is an important user-facing change, PR or related issue has a 'changelog' label
  • If this includes an internal dependency change, a link to the diff is provided

Reviewer checklist

  • Automated test coverage is satisfactory
  • PR is fully functional
  • PR has been tested for accessibility regressions
  • External dependency files were updated if necessary (yarn and pip)
  • Documentation is updated
  • Contributor is in AUTHORS.md

@github-actions github-actions bot added DEV: backend Python, databases, networking, filesystem... SIZE: small labels Jul 21, 2023
Copy link
Member

@bjester bjester left a comment

Choose a reason for hiding this comment

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

Thanks for tackling this! Could you make one small change, for simplicity?

kolibri/core/discovery/utils/network/client.py Outdated Show resolved Hide resolved
Copy link
Member

@bjester bjester left a comment

Choose a reason for hiding this comment

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

Thanks for resolving my last feedback. It looks good.

Now I see the test is failing, so just a couple fixes for the test to pass and this to be merged

kolibri/core/discovery/test/test_network_utils.py Outdated Show resolved Hide resolved
kolibri/core/discovery/test/test_network_utils.py Outdated Show resolved Hide resolved
@bjester bjester marked this pull request as ready for review July 24, 2023 17:07
@bjester bjester added the TODO: needs review Waiting for review label Jul 24, 2023
@mhasbini
Copy link
Contributor Author

mhasbini commented Jul 25, 2023

@bjester Thanks again for checking. I addressed the test & lint issues.

btw NetworkClient() is one part of this change, there are a couple of other places that uses requests directly and they won't have the update UA.

I was thinking I could either:

  • Refactor these imports to use NetworkClient().
  • If the above is not recommended for certain reasons then create a new factory for requests that have this custom user agent and NetworkClient can then extends it.

lmk what's the recommended approach.

@bjester
Copy link
Member

bjester commented Jul 26, 2023

@mhasbini There are still some linting failures that I can see. If you install pre-commit (instructions), it will fix those during commit. Or you can do so manually by looking at the failure in the PR check.

Could you please comment on this issue so I can make you the assignee?

Yes you're right, there are several usages of requests that bypass the NetworkClient. We do want to refactor those to use it but that's definitely out of scope of this issue. I think what you've done here is sufficient for the assigned issue.

Refactoring existing usage of requests was tracked as a task within this issue. I created a new and separate issue from it which we can assign you if you're interested in continuing with that. It'll be a heavy refactor in some places, but it's worthwhile and you can take your time with it. If you'd like to work on it, please comment on the issue.

@mhasbini
Copy link
Contributor Author

@bjester Thanks for the clarification!
Unfortunately my local env is a mess rn and I couldn't setup pre-commit hook. I tried to fix the issues by manually doing the changes from the lint output in the CI.

Copy link
Member

@bjester bjester left a comment

Choose a reason for hiding this comment

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

Thank you @mhasbini!

@bjester bjester merged commit e84fd44 into learningequality:develop Jul 27, 2023
34 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
DEV: backend Python, databases, networking, filesystem... SIZE: small TODO: needs review Waiting for review
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add custom user-agent to NetworkClient and external API calls
2 participants