-
Notifications
You must be signed in to change notification settings - Fork 216
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
Make User-Agent a default header #3828
Changes from 5 commits
5f5f55f
5c32dcf
b7ab1f8
db8fe6b
ad6b3da
c4c7f39
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -7,6 +7,7 @@ | |
from requests.exceptions import JSONDecodeError | ||
|
||
import oauth2 | ||
from common.loader import provider_details as prov | ||
|
||
|
||
# pytest_socket will not be available in production, so we must create a shim for | ||
|
@@ -42,12 +43,13 @@ class DelayedRequester: | |
delay: an integer giving the minimum number of seconds to wait | ||
between consecutive requests via the `get` method. | ||
headers: a dict that will be passed in all requests, unless overridden | ||
by kwargs in specific calls to the get method | ||
by kwargs in specific calls to the `get` method | ||
""" | ||
|
||
def __init__(self, delay=0, headers=None): | ||
def __init__(self, delay: int = 0, headers: dict | None = None): | ||
headers = {} if headers is None else headers | ||
self._DELAY = delay | ||
self.headers = headers or {} | ||
self.headers = {"User-Agent": prov.UA_STRING} | headers | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why do we default here in addition to adding this as a default in the ProviderDataIngester? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. That was the suggestion of the issue, and I went that route first, but it turns out it wasn't enough to set the default header. I leave it after updating the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 😮 That's so strange -- do you mean setting it as the default in If it can be added in only one place, I do agree about adding it in the requester instead of the ProviderDataIngester, since that gets complicated with subclasses that override There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Yes, the thing is the
It's a possibility, I haven't checked but this isn't the issue here, as I explained above. We should be safe with these changes! |
||
self._last_request = 0 | ||
self.session = requests.Session() | ||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I guess if we want to match the API's new variables, it should be an environment variable of
CANONICAL_DOMAIN
with origin derived from it, but I don't know if that was a goal with this PR. It doesn't matter to me either way, as there's so little overlap between the variables for each I don't think we need to be concerned with having them match except when the names are this similar, it would be easier to make a quick mistake.To clarify, not a suggestion for a change, just noting the slight difference, will at least help me keep it in mind during infra work to migrate Airflow's environment variables to the new approach.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, I intended to make the change aligned with your on moving the domain :) I thought the
CANONICAL_DOMAIN
was a variable we could skip here, but you're right. It would be better to match the API's variables in this case.Done ✅