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

Let the transport handles bad urls #12106

Merged
merged 6 commits into from Jun 18, 2020
Merged

Let the transport handles bad urls #12106

merged 6 commits into from Jun 18, 2020

Conversation

lmazuel
Copy link
Member

@lmazuel lmazuel commented Jun 17, 2020

See #11048

If a bad combination of parametrized host + incorrect client creation happen, do not crash while trying to build the Url, but build something, and let the transport decides what to do.

For requests, the new trace is now:

  File "c:\users\lmazuel\git\azure-sdk-for-python\sdk\core\azure-core\azure\core\pipeline\transport\_requests_basic.py", line 284, in send
    raise error
azure.core.exceptions.ServiceRequestError: Invalid URL 'text/analytics/v3.0/krpratic-textanalytics.cognitiveservices.azure.com//text/analytics/v3.0/sentiment?showStats=false': No schema supplied. Perhaps you meant http://text/analytics/v3.0/krpratic-textanalytics.cognitiveservices.azure.com//text/analytics/v3.0/sentiment?showStats=false?

For aiohttp:

aiohttp.client_exceptions.InvalidURL: text/analytics/v3.0/krpratic-textanalytics.cognitiveservices.azure.com//text/analytics/v3.0/sentiment?showStats=false

which is way better than the current error you can see on issue #11048

File "C:\Users\krpratic\azure-sdk-for-python\env\lib\site-packages\azure\core\pipeline\transport\_base.py", line 695, in format_url
    base = self._base_url.format(**kwargs).rstrip("/")
KeyError: 'Endpoint'

EDIT: Will now raise an exception

"The value provided for the url part Endpoint was incorrect, and resulted in an invalid url"

@lmazuel lmazuel added the Client This issue points to a problem in the data-plane of the library. label Jun 17, 2020
@lmazuel lmazuel changed the title Let the transport handle bad urls Let the transport handles bad urls Jun 17, 2020
@lmazuel lmazuel marked this pull request as ready for review June 17, 2020 23:15
@lmazuel lmazuel requested a review from xiangyan99 as a code owner June 17, 2020 23:15
kristapratico
kristapratico previously approved these changes Jun 17, 2020
Copy link
Member

@kristapratico kristapratico 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 so much for doing this!

@xiangyan99
Copy link
Member

If the input kwargs do not satisfy template, why not raise error?

I have some concerns if we modify the template silently.

Maybe we should just give a more descriptive error message?

@lmazuel
Copy link
Member Author

lmazuel commented Jun 17, 2020

What error would you raise? You don't have enough information other that "something is wrong", building the url leniently and let the transport decide if it's malformed sounds fair to me. What are your concerns?

@xiangyan99
Copy link
Member

My concern is the case that after we skip some components, it is still a valid URL but returns different response. e.g. api_version_number. Because we skip it silently for user, it may confuse users.

@lmazuel
Copy link
Member Author

lmazuel commented Jun 18, 2020

@xiangyan99 if I catch the error, only thing I know is that something the customer provided is not right. I don't know if it's a client parameter (like endpoint), I don't know if it's an operation parameter, I don't know if it's both.

I could raise something like this:

Unable to build a valid Url, one of your client parameter or operation parameter is invalid, and doesn't allow to build a correct url.

Thoughts?

@annatisch
Copy link
Member

We can likely include the contents of kwargs in the error - as I think these values will mostly be user-supplied, with some values added by the generator, but still potentially useful in debugging.

@xiangyan99
Copy link
Member

I think the point is if there is something wrong, we would like it to fail on compile time (when building the url) than un-deterministic result (may or may not fail when sending it to server). Your ideas?

@lmazuel
Copy link
Member Author

lmazuel commented Jun 18, 2020

kwargs is empty, the only thing we know is that Endpoint (the Swagger template part) was invalid. I don't have the Python name related to that Swagger template part (it's likely the lower case in snake case, like FooBar template part would be foo_bar parameter name, but I don't have the actual mapping)

is this better:

The value provided for the url part Endpoint was incorrect, and resulted in an invalid url

Thoughts?

Edit: Endpoint I mentioned could be anything, the Swagger decides, could be UrlEndpoint, UrlBase, etc. Endpoint is the example for Text Analytics here

@kristapratico
Copy link
Member

I've seen users run into this error in two ways:

  1. accidentally chop off https
  2. define the endpoint ending with a comma (making it a tuple) e.g.:
    endpoint = "https://python-textanalytics.cognitiveservices.azure.com/",

In the first case, we do get a good error back from the transport. In the second case, we get this:

azure.core.exceptions.ServiceRequestError: No connection adapters were found for 'text/analytics/v3.0/('https://python-textanalytics.cognitiveservices.azure.com/',)/text/analytics/v3.0/sentiment?showStats=false'

... which is not so good.

So in that case I would be happy with this:

The value provided for the url part Endpoint was incorrect, and resulted in an invalid url

@rakshith91
Copy link
Contributor

rakshith91 commented Jun 18, 2020

accidentally chop off https is often handles individually by clients - we do it in storage, search etc.
I think this would end up with a KeyError somewhere.

@lmazuel
Copy link
Member Author

lmazuel commented Jun 18, 2020

@annatisch @rakshith91 @kristapratico @xiangyan99 I pushed an update, how does it sound?

kristapratico
kristapratico previously approved these changes Jun 18, 2020
Copy link
Member

@kristapratico kristapratico 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 good with this change

xiangyan99
xiangyan99 previously approved these changes Jun 18, 2020
@lmazuel lmazuel dismissed stale reviews from xiangyan99 and kristapratico via 872f213 June 18, 2020 20:35
@lmazuel lmazuel merged commit f5d1a6d into master Jun 18, 2020
@lmazuel lmazuel deleted the endpoint_keyerror branch June 18, 2020 22:25
iscai-msft added a commit to iscai-msft/azure-sdk-for-python that referenced this pull request Jun 22, 2020
…into regenerate_certs

* 'master' of https://github.com/Azure/azure-sdk-for-python:
  [text analytics] remove duplicate platform info in user agent (Azure#12123)
  [form recognizer] remove duplicate platform info in user agent (Azure#12124)
  fix broken links (Azure#12100)
  Document "<unchanged>" for DataSourceCredentials.connectionString if it is empty (Azure#12129)
  Let the transport handles bad urls (Azure#12106)
  Remove Unneeded Reference to repository resource (Azure#11929)
  enable logging for tests (Azure#12110)
  fix network in batch testcase (Azure#12114)
  update test recording for appservice (Azure#12116)
  Add test for connection monitor and fix test api version. (Azure#12113)
  Minor root readme and mgmt quickstart update for Track 2 mgmt sdk (Azure#12112)
  Quickstart for Track 2 preview management libraries and update root readme for track 2 (Azure#11384)
  Seg fault fix (Azure#11933)
iscai-msft added a commit to iscai-msft/azure-sdk-for-python that referenced this pull request Jun 22, 2020
…into regenerate_keys

* 'master' of https://github.com/Azure/azure-sdk-for-python:
  [text analytics] remove duplicate platform info in user agent (Azure#12123)
  [form recognizer] remove duplicate platform info in user agent (Azure#12124)
  fix broken links (Azure#12100)
  Document "<unchanged>" for DataSourceCredentials.connectionString if it is empty (Azure#12129)
  Let the transport handles bad urls (Azure#12106)
  Remove Unneeded Reference to repository resource (Azure#11929)
  enable logging for tests (Azure#12110)
  fix network in batch testcase (Azure#12114)
  update test recording for appservice (Azure#12116)
  Add test for connection monitor and fix test api version. (Azure#12113)
  Minor root readme and mgmt quickstart update for Track 2 mgmt sdk (Azure#12112)
  Quickstart for Track 2 preview management libraries and update root readme for track 2 (Azure#11384)
  Seg fault fix (Azure#11933)
iscai-msft added a commit to iscai-msft/azure-sdk-for-python that referenced this pull request Jun 22, 2020
…into regenerate_secrets

* 'master' of https://github.com/Azure/azure-sdk-for-python: (39 commits)
  [text analytics] remove duplicate platform info in user agent (Azure#12123)
  [form recognizer] remove duplicate platform info in user agent (Azure#12124)
  fix broken links (Azure#12100)
  Document "<unchanged>" for DataSourceCredentials.connectionString if it is empty (Azure#12129)
  Let the transport handles bad urls (Azure#12106)
  Remove Unneeded Reference to repository resource (Azure#11929)
  enable logging for tests (Azure#12110)
  fix network in batch testcase (Azure#12114)
  update test recording for appservice (Azure#12116)
  Add test for connection monitor and fix test api version. (Azure#12113)
  Minor root readme and mgmt quickstart update for Track 2 mgmt sdk (Azure#12112)
  Quickstart for Track 2 preview management libraries and update root readme for track 2 (Azure#11384)
  Seg fault fix (Azure#11933)
  [formrecognizer] update formrecognizer links to new aka.ms naming (Azure#12079)
  changes in samples tests (Azure#12090)
  readme & sample updates (Azure#12095)
  Update Key Vault minimum azure-core to 1.4.0 (Azure#12074)
  [formrecognizer] test parity with other languages (Azure#12059)
  syncing missing changelog items (Azure#12089)
  updating doc references (Azure#12086)
  ...
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Azure.Core Client This issue points to a problem in the data-plane of the library.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants