Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions sdk/core/azure-core/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@
- Added `ODataV4Format.as_dict()` to convert parsed OData V4 errors, including nested details and model-valued inner errors, to JSON-compatible dictionaries for generated model serialization, preserving `None` values and empty collections.
- Added `azure-deprecating` to the default allowed headers list in `HttpLoggingPolicy`, so deprecation notification headers are logged without redaction.

### Bugs Fixed

- Fixed `HttpLoggingPolicy.allowed_header_names` and the `allowed_query_params` sets of `HttpLoggingPolicy` and `DistributedTracingPolicy` ignoring changes made with in-place set operators (`|=`, `-=`, `&=`, `^=`) and with `difference_update`, `intersection_update` and `symmetric_difference_update`.

## 1.41.0 (2026-05-07)

### Features Added
Expand Down
46 changes: 46 additions & 0 deletions sdk/core/azure-core/azure/core/utils/_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import datetime
import sys
from typing import (
AbstractSet,
Any,
AsyncContextManager,
Iterable,
Expand Down Expand Up @@ -182,6 +183,51 @@ def update(self, *others):
for item in other:
self.add(item)

def difference_update(self, *others):
for other in others:
for item in other:
self.discard(item)

def intersection_update(self, *others):
for other in others:
keep = CaseInsensitiveSet(other)
for item in list(self):
if item not in keep:
self.discard(item)

def symmetric_difference_update(self, other):
for item in CaseInsensitiveSet(other):
if item in self:
self.discard(item)
else:
self.add(item)

# The in-place operators of the built-in set bypass the methods above and would leave
# the lowercase cache out of sync, so route them through the cache-aware methods.
def __ior__(self, other): # type: ignore[misc] # same as typeshed's set
if not isinstance(other, AbstractSet):
return NotImplemented
self.update(other)
return self

def __iand__(self, other): # type: ignore[misc] # same as typeshed's set
if not isinstance(other, AbstractSet):
return NotImplemented
self.intersection_update(other)
return self

def __isub__(self, other): # type: ignore[misc] # same as typeshed's set
if not isinstance(other, AbstractSet):
return NotImplemented
self.difference_update(other)
return self

def __ixor__(self, other): # type: ignore[misc] # same as typeshed's set
if not isinstance(other, AbstractSet):
return NotImplemented
self.symmetric_difference_update(other)
return self

def clear(self):
super().clear()
self._lower_to_original = {}
Expand Down
9 changes: 9 additions & 0 deletions sdk/core/azure-core/tests/test_http_logging_policy.py
Original file line number Diff line number Diff line change
Expand Up @@ -388,3 +388,12 @@ def emit(self, record):
assert messages_request[0] == "Request URL: 'http://localhost/?api-version=1.0&country=france&city=REDACTED'"

mock_handler.reset()


def test_http_logger_allowed_header_names_inplace_operators():
policy = HttpLoggingPolicy()
policy.allowed_header_names |= {"x-custom-header"}
assert policy._redact_header("X-Custom-Header", "value") == "value"

policy.allowed_header_names -= {"x-ms-request-id"}
assert policy._redact_header("x-ms-request-id", "value") == HttpLoggingPolicy.REDACTED_PLACEHOLDER
53 changes: 53 additions & 0 deletions sdk/core/azure-core/tests/test_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -350,3 +350,56 @@ def test_multiple(self):
assert len(s) == 1
s.discard("foo")
assert len(s) == 0

def test_inplace_or(self):
s = CaseInsensitiveSet(["Foo"])
s |= {"Bar"}
assert isinstance(s, CaseInsensitiveSet)
assert "Bar" in s
assert "bar" in s
s |= {"FOO"}
assert len(s) == 2

def test_inplace_sub(self):
s = CaseInsensitiveSet(["Foo", "Bar"])
s -= {"foo"}
assert isinstance(s, CaseInsensitiveSet)
assert "Foo" not in s
assert "bar" in s
assert len(s) == 1

def test_difference_update(self):
s = CaseInsensitiveSet(["Foo", "Bar", "Baz"])
s.difference_update(["FOO"], ["baz"])
assert "foo" not in s
assert "baz" not in s
assert "bar" in s
assert len(s) == 1

def test_intersection_update(self):
s = CaseInsensitiveSet(["Foo", "Bar"])
s.intersection_update(["FOO", "Baz"])
assert "Foo" in s
assert "Bar" not in s
assert list(s) == ["Foo"]

s = CaseInsensitiveSet(["Foo", "Bar"])
s &= {"bar"}
assert isinstance(s, CaseInsensitiveSet)
assert "Foo" not in s
assert "BAR" in s
assert len(s) == 1

def test_symmetric_difference_update(self):
s = CaseInsensitiveSet(["Foo", "Bar"])
s.symmetric_difference_update(["FOO", "Baz"])
assert "foo" not in s
assert "bar" in s
assert "baz" in s
assert len(s) == 2

s ^= {"BAZ", "Qux"}
assert isinstance(s, CaseInsensitiveSet)
assert "baz" not in s
assert "qux" in s
assert len(s) == 2
Loading