-
Notifications
You must be signed in to change notification settings - Fork 2.9k
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
[core] add query kwarg to HttpRequest #16942
Conversation
|
||
request = HttpRequest("GET", url="a/b/c?t=y", query={"g": "h"}) | ||
|
||
self.assertIn(request.url, ["a/b/c?g=h&t=y", "a/b/c?t=y&g=h"]) |
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'd like to see a test when there was no query in the first place (to also check we add correctly the ?
:param dict params: A dictionary of parameters. | ||
""" | ||
params = params or {} |
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.
@lmazuel want to call this out. This way, if users pass in params=None
or query=None
from the kwarg in HttpRequest
, we don't throw a None
error and we tack on the ?
to the end of the url
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.
If params is not a dict, what's our expected behavior? and in which case, user will set it explicit None?
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.
params is typed as a Dict[str, str]
. i'm not quite sure about the use case of users passing inNone
for query, but I added this bc @lmazuel wanted to make sure if query is
None, we add the
?` at the end of the url
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.
You should be able to pass in a number or a boolean query parameter value, no?
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.
that's true, let me change this to Dict[str, Any]
self.method = method | ||
self.url = url | ||
self.headers = _case_insensitive_dict(headers) | ||
self.files = files | ||
self.data = data | ||
self.multipart_mixed_info = None # type: Optional[Tuple] | ||
if "query" in kwargs: |
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.
Let's just to a pop
with a default value. No need to look it up twice :).
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.
If query is not set, we don't want to call self.format_parameters, right? (given self.format_parameters() has side effect even the input is None)
@@ -222,16 +222,20 @@ class HttpRequest(object): | |||
:param files: Files list. | |||
:param data: Body to be sent. | |||
:type data: bytes or str. | |||
:keyword dict[str,any] query: A dictionary of query parameters you would like to include | |||
in your request. We automatically format your query params into the inputted url. |
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.
How would we format something like query={ 'items': [ 'a', 'b', 'c', 'd' ] }
?
I believe we need to be very explicit about if/when/what we encode and how (and this should also translate into specific test cases to make sure we don't break stuff)
@@ -222,16 +222,20 @@ class HttpRequest(object): | |||
:param files: Files list. | |||
:param data: Body to be sent. | |||
:type data: bytes or str. | |||
:keyword dict[str,any] query: A dictionary of query parameters you would like to include |
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.
The query
parameter should take a sequence of key-value tuples in addition to a dict
. Many services allow/require the same query parameter multiple times (something similar to http://contoso.com/api?item=1&item=2&item=7
)
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.
@johanste would it be ok to keep it as Dict[str, Any]
for this release so we get the query
kwarg in place? Currently core only accepts Dict[str, Any]
in format_parameters
, so this would be at parity. For next release, I can open an issue to expand query to allow in lists of tuples etc, following httpx's possible values
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.
We should take a look at what other HTTP stacks do (e.g. requests parameters
and httpx's params
) before we lock down this API.
This pull request is protected by Check Enforcer. What is Check Enforcer?Check Enforcer helps ensure all pull requests are covered by at least one check-run (typically an Azure Pipeline). When all check-runs associated with this pull request pass then Check Enforcer itself will pass. Why am I getting this message?You are getting this message because Check Enforcer did not detect any check-runs being associated with this pull request within five minutes. This may indicate that your pull request is not covered by any pipelines and so Check Enforcer is correctly blocking the pull request being merged. What should I do now?If the check-enforcer check-run is not passing and all other check-runs associated with this PR are passing (excluding license-cla) then you could try telling Check Enforcer to evaluate your pull request again. You can do this by adding a comment to this pull request as follows: What if I am onboarding a new service?Often, new services do not have validation pipelines associated with them, in order to bootstrap pipelines for a new service, you can issue the following command as a pull request comment: |
…into add_query_kwarg * 'master' of https://github.com/Azure/azure-sdk-for-python: (69 commits) march release (Azure#16966) Release of Device Update for IoT Hub SDK for Python. (Azure#17005) Add Get-AllPackageInfoFromRepo (Azure#16947) Track1 package is incorrectly set as track2 (Azure#17075) [text analytics] add normalized_text (Azure#17074) Renaming with_token identity function (Azure#17066) Adapt to azure core's cloud event (Azure#17063) align perf tests with js (Azure#17069) [Perfstress][Storage] Added FileShare perf tests (Azure#15834) [formrecognizer] Adding custom forms perf test (Azure#16969) Fix LanguageShort typo (Azure#17068) sas creds updates (Azure#17065) [eventgrid] Fix Sample eh (Azure#17064) [Perfstress][Storage] Added Datalake perf tests (Azure#15861) [text analytics] Healthcare n-ary relations (Azure#16997) ServiceBus dict-representation acceptance and kwarg-update functionality (Azure#14807) [text analytics] add perf tests (Azure#17060) Add cloud event to core (Azure#16800) [Perf] Small fixes to storage-blob (Azure#17055) [EG] Regenerate Code (Azure#17053) ...
…into add_query_kwarg * 'master' of https://github.com/Azure/azure-sdk-for-python: EG - more docs imrpovement (Azure#17079) [EventHubs] add logging.info to warn the usage of partition key of non-string type (Azure#17057)
putting on the backburner, so will close this PR |
fixes #16941