-
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] remove chardet dep from azure.core.rest #19962
Conversation
nope :p |
try: | ||
encoding = chardet.detect(response.content)["encoding"] | ||
except ResponseNotReadError: | ||
pass | ||
if encoding is None or not lookup_encoding(encoding): | ||
return 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.
We want to default to "utf-8"("utf-8-sig"), right?
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.
After talking with @lmazuel, we don't default the value of self.encoding
to utf-8-sig
. We do that when we're deserializing for the text
property, which I've added code for in def decode_to_text
if encoding: | ||
return content.decode(encoding) | ||
# 1. We try utf-8-sig | ||
decoder = codecs.getincrementaldecoder("utf-8-sig")(errors="strict") |
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.
followed httpx's lead, and included trying to deserialize with windows 1252 @lmazuel . Lmk if we want to remove this
https://github.com/encode/httpx/blob/master/httpx/_models.py#L1317
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 utf-8-sig didn't work, utf-8 won't as well (so no need to do it later), utf-8-sig is a super-set of utf-8.
I wouldn't try cp1252 yet, httpx does it for HTML pages in old MS servers (we don't do that). Let's not fix what is not broken :)
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.
ok sounds good, will simplify my code too. thanks!
sdk/core/azure-core/CHANGELOG.md
Outdated
@@ -8,6 +8,8 @@ | |||
|
|||
### Key Bugs Fixed | |||
|
|||
- Removed `chardet` dependency in `azure.core.rest`. |
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.
Do we want to clarify this is a breaking change?
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'm not sure, @annatisch do you think we should clarify it's breaking, because this is in a provisional package? Worried we're being scary for non-azure.core.rest users for nothing
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.
@xiangyan99 talked to @lmazuel and he recommended adding a section like "Breaking changes in provisional package", so I added that to the changelog and listed this fix under there. Thanks!
@@ -168,7 +168,7 @@ def test_json(send_request): | |||
request=HttpRequest("GET", "/basic/json"), | |||
) | |||
assert response.json() == {"greeting": "hello", "recipient": "world"} | |||
assert response.encoding == 'utf-8-sig' # for requests, we use utf-8-sig instead of utf-8 bc of requests behavior |
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.
Do we still need these three tests? Maybe one is good enought?
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.
Not quite sure which tests you mean by the three tests, but I feel like more tests is better, so might as well not get rid of them
/azp run python - core - ci |
Azure Pipelines successfully started running 1 pipeline(s). |
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 change looks good. Please confirm the changelog.
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_chardet_dep * 'main' of https://github.com/Azure/azure-sdk-for-python: (35 commits) `azure-applicationinsights` Hyperlinks need sphinx style formatting (Azure#19993) update version and changelog (Azure#20034) Rename AZURE_POD_IDENTITY_TOKEN_URL -> AZURE_POD_IDENTITY_AUTHORITY_HOST (Azure#19867) add sample for raw_response_hook (Azure#19985) cut hard dependency on requests (Azure#19930) Update ci.yml (Azure#20028) Update ci.yml (Azure#20026) Update PythonSdkLiveTest.yml (Azure#19999) [AutoRelease] t2-recoveryservicessiterecovery-2021-07-28-40357 (Azure#19970) [AutoRelease] t2-storagecache-2021-07-29-63871 (Azure#19987) Minor changes in docs (Azure#20016) Add Logs Batch query results (Azure#20013) Rename query (Azure#19952) d218371 (Azure#20009) Update CHANGELOG.md (Azure#20006) [Batch] Data plane SDK v11.0.0 (Azure#19889) [AutoRelease] t2-batch-2021-07-30-27488 (Azure#19996) add ga id to index (Azure#19995) Edit pass on Monitor Query README file (Azure#19979) Move stress testing scripts to eng/common (Azure#19994) ...
sdk/core/azure-core/CHANGELOG.md
Outdated
### Breaking Changes | ||
### Breaking Changes in the Provisional `azure.core.rest` package | ||
|
||
- Removed `chardet` dependency in `azure.core.rest`. Breaking because we removed the step that used `chardet` to inspect the response encoding |
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 would phrase it as impact on customer, not internal details:
azure.core.rest won't try to guess the charset anymore if it was impossible to extract it from HttpResponse analysis
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.
Sounds good!
No description provided.