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

[core] add query kwarg to HttpRequest #16942

Closed
wants to merge 12 commits into from

Conversation

iscai-msft
Copy link
Contributor

fixes #16941


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"])
Copy link
Member

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 {}
Copy link
Contributor Author

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

Copy link
Member

@xiangyan99 xiangyan99 Mar 1, 2021

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?

Copy link
Contributor Author

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

Copy link
Member

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?

Copy link
Contributor Author

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:
Copy link
Member

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 :).

Copy link
Member

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.
Copy link
Member

@johanste johanste Mar 2, 2021

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
Copy link
Member

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)

Copy link
Contributor Author

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

Copy link
Member

@johanste johanste left a 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.

@check-enforcer
Copy link

check-enforcer bot commented Mar 4, 2021

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:
/check-enforcer evaluate
Typically evaulation only takes a few seconds. If you know that your pull request is not covered by a pipeline and this is expected you can override Check Enforcer using the following command:
/check-enforcer override
Note that using the override command triggers alerts so that follow-up investigations can occur (PRs still need to be approved as normal).

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:
/azp run prepare-pipelines
This will run a pipeline that analyzes the source tree and creates the pipelines necessary to build and validate your pull request. Once the pipeline has been created you can trigger the pipeline using the following comment:
/azp run python - [service] - ci

…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)
@iscai-msft
Copy link
Contributor Author

putting on the backburner, so will close this PR

@iscai-msft iscai-msft closed this Mar 4, 2021
@iscai-msft iscai-msft deleted the add_query_kwarg branch May 13, 2021 22:36
openapi-sdkautomation bot pushed a commit to AzureSDKAutomation/azure-sdk-for-python that referenced this pull request Dec 28, 2021
Review request for Microsoft.ContainerService to add version preview/2021-11-01-preview (Azure#17104)

* Adds base for updating Microsoft.ContainerService from version stable/2021-10-01 to version 2021-11-01-preview

* Updates readme

* Updates API version in new specs and examples

* feat: define OIDC issuer profile (Azure#16834)

* feat: define OIDC issuer profile

* fix: add `OIDC` to custom-wrods.txt

* doc: update description

* style: fix style check

* fix: add type

* add enableNamespaceResources in Managed Cluster (Azure#16835)

* add enableNamespaceResources in Managed Cluster

* update example for enableNamespaceResources

* changed description of enableNamespaceresources

* change description for enableNamespaceResources

* feat: define currentKubernetesVersion (Azure#16878)

Add property currentKubernetesVersion for feature AliasMinorVersion

* add message of the day for Linux nodes (Azure#16942)

* [AKS] feat: add python SDK generation for 1001/1101-preview api (Azure#16895)

* feat: add python SDK generation for 1001/1101-preview api

* fix: missing tag

* fix: update path

* fix: update path

* fix: typo

* feat: update readme.python.md

* Rebased from main to dev branch (Azure#17081)

Co-authored-by: Anumita Shenoy <anumitashenoy@gmail.com>
Co-authored-by: Jianping Zeng <zjpjack@users.noreply.github.com>
Co-authored-by: Ace Eldeib <alexeldeib@gmail.com>
Co-authored-by: Tong Chen <45081443+tonche@users.noreply.github.com>
openapi-sdkautomation bot pushed a commit to AzureSDKAutomation/azure-sdk-for-python that referenced this pull request Jan 5, 2022
Review request for Microsoft.ContainerService to add version preview/2021-11-01-preview (Azure#17104)

* Adds base for updating Microsoft.ContainerService from version stable/2021-10-01 to version 2021-11-01-preview

* Updates readme

* Updates API version in new specs and examples

* feat: define OIDC issuer profile (Azure#16834)

* feat: define OIDC issuer profile

* fix: add `OIDC` to custom-wrods.txt

* doc: update description

* style: fix style check

* fix: add type

* add enableNamespaceResources in Managed Cluster (Azure#16835)

* add enableNamespaceResources in Managed Cluster

* update example for enableNamespaceResources

* changed description of enableNamespaceresources

* change description for enableNamespaceResources

* feat: define currentKubernetesVersion (Azure#16878)

Add property currentKubernetesVersion for feature AliasMinorVersion

* add message of the day for Linux nodes (Azure#16942)

* [AKS] feat: add python SDK generation for 1001/1101-preview api (Azure#16895)

* feat: add python SDK generation for 1001/1101-preview api

* fix: missing tag

* fix: update path

* fix: update path

* fix: typo

* feat: update readme.python.md

* Rebased from main to dev branch (Azure#17081)

Co-authored-by: Anumita Shenoy <anumitashenoy@gmail.com>
Co-authored-by: Jianping Zeng <zjpjack@users.noreply.github.com>
Co-authored-by: Ace Eldeib <alexeldeib@gmail.com>
Co-authored-by: Tong Chen <45081443+tonche@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[core] add query kwarg for HttpRequest
4 participants