Skip to content

Commit e3b3b8a

Browse files
author
Yalin Li
authored
[AppConfig] Fix a bug for "etag" and Fix pylint-next errors (#33684)
1 parent 26d042a commit e3b3b8a

File tree

3 files changed

+61
-30
lines changed

3 files changed

+61
-30
lines changed

sdk/appconfiguration/azure-appconfiguration/CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
### Breaking Changes
88

99
### Bugs Fixed
10+
- Fixed a bug in consuming "etag" value in sync operation `set_configuration_setting()`.
1011

1112
### Other Changes
1213

sdk/appconfiguration/azure-appconfiguration/azure/appconfiguration/_azure_appconfiguration_client.py

Lines changed: 30 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -210,6 +210,8 @@ def get_configuration_setting(
210210
label: Optional[str] = None,
211211
etag: Optional[str] = "*",
212212
match_condition: MatchConditions = MatchConditions.Unconditionally,
213+
*,
214+
accept_datetime: Optional[Union[datetime, str]] = None,
213215
**kwargs,
214216
) -> Union[None, ConfigurationSetting]:
215217
"""Get the matched ConfigurationSetting from Azure App Configuration service
@@ -240,7 +242,6 @@ def get_configuration_setting(
240242
key="MyKey", label="MyLabel"
241243
)
242244
"""
243-
accept_datetime = kwargs.pop("accept_datetime", None)
244245
if isinstance(accept_datetime, datetime):
245246
accept_datetime = str(accept_datetime)
246247

@@ -314,6 +315,8 @@ def set_configuration_setting(
314315
self,
315316
configuration_setting: ConfigurationSetting,
316317
match_condition: MatchConditions = MatchConditions.Unconditionally,
318+
*,
319+
etag: Optional[str] = None,
317320
**kwargs,
318321
) -> ConfigurationSetting:
319322
"""Add or update a ConfigurationSetting.
@@ -325,7 +328,8 @@ def set_configuration_setting(
325328
:type configuration_setting: ~azure.appconfiguration.ConfigurationSetting
326329
:param match_condition: The match condition to use upon the etag
327330
:type match_condition: ~azure.core.MatchConditions
328-
:keyword str etag: check if the ConfigurationSetting is changed. Set None to skip checking etag
331+
:keyword str etag: check if the ConfigurationSetting is changed. \
332+
Will use the value from param configuration_setting if not set.
329333
:return: The ConfigurationSetting returned from the service
330334
:rtype: ~azure.appconfiguration.ConfigurationSetting
331335
:raises: :class:`~azure.core.exceptions.HttpResponseError`, \
@@ -367,7 +371,7 @@ def set_configuration_setting(
367371
key=key_value.key, # type: ignore
368372
label=key_value.label,
369373
if_match=prep_if_match(configuration_setting.etag, match_condition),
370-
if_none_match=prep_if_none_match(configuration_setting.etag, match_condition),
374+
if_none_match=prep_if_none_match(etag or configuration_setting.etag, match_condition),
371375
headers=custom_headers,
372376
error_map=error_map,
373377
)
@@ -377,7 +381,13 @@ def set_configuration_setting(
377381

378382
@distributed_trace
379383
def delete_configuration_setting( # pylint:disable=delete-operation-wrong-return-type
380-
self, key: str, label: Optional[str] = None, **kwargs
384+
self,
385+
key: str,
386+
label: Optional[str] = None,
387+
*,
388+
etag: Optional[str] = None,
389+
match_condition: MatchConditions = MatchConditions.Unconditionally,
390+
**kwargs,
381391
) -> ConfigurationSetting:
382392
"""Delete a ConfigurationSetting if it exists
383393
@@ -406,8 +416,6 @@ def delete_configuration_setting( # pylint:disable=delete-operation-wrong-retur
406416
key="MyKey", label="MyLabel"
407417
)
408418
"""
409-
etag = kwargs.pop("etag", None)
410-
match_condition = kwargs.pop("match_condition", MatchConditions.Unconditionally)
411419
custom_headers: Mapping[str, Any] = CaseInsensitiveDict(kwargs.get("headers"))
412420
error_map: Dict[int, Any] = {409: ResourceReadOnlyError}
413421
if match_condition == MatchConditions.IfNotModified:
@@ -433,7 +441,13 @@ def delete_configuration_setting( # pylint:disable=delete-operation-wrong-retur
433441

434442
@distributed_trace
435443
def list_revisions(
436-
self, key_filter: Optional[str] = None, label_filter: Optional[str] = None, **kwargs
444+
self,
445+
key_filter: Optional[str] = None,
446+
label_filter: Optional[str] = None,
447+
*,
448+
accept_datetime: Optional[Union[datetime, str]] = None,
449+
fields: Optional[List[str]] = None,
450+
**kwargs,
437451
) -> ItemPaged[ConfigurationSetting]:
438452
"""
439453
Find the ConfigurationSetting revision history, optionally filtered by key, label and accept_datetime.
@@ -470,19 +484,17 @@ def list_revisions(
470484
for item in filtered_revisions:
471485
pass # do something
472486
"""
473-
accept_datetime = kwargs.pop("accept_datetime", None)
474487
if isinstance(accept_datetime, datetime):
475488
accept_datetime = str(accept_datetime)
476-
select = kwargs.pop("fields", None)
477-
if select:
478-
select = ["locked" if x == "read_only" else x for x in select]
489+
if fields:
490+
fields = ["locked" if x == "read_only" else x for x in fields]
479491

480492
try:
481493
return self._impl.get_revisions( # type: ignore
482494
label=label_filter,
483495
key=key_filter,
484496
accept_datetime=accept_datetime,
485-
select=select,
497+
select=fields,
486498
cls=lambda objs: [ConfigurationSetting._from_generated(x) for x in objs],
487499
**kwargs,
488500
)
@@ -491,7 +503,12 @@ def list_revisions(
491503

492504
@distributed_trace
493505
def set_read_only(
494-
self, configuration_setting: ConfigurationSetting, read_only: bool = True, **kwargs
506+
self,
507+
configuration_setting: ConfigurationSetting,
508+
read_only: bool = True,
509+
*,
510+
match_condition: MatchConditions = MatchConditions.Unconditionally,
511+
**kwargs,
495512
) -> ConfigurationSetting:
496513
"""Set a configuration setting read only
497514
@@ -519,7 +536,6 @@ def set_read_only(
519536
read_only_config_setting = client.set_read_only(config_setting, read_only=False)
520537
"""
521538
error_map: Dict[int, Any] = {}
522-
match_condition = kwargs.pop("match_condition", MatchConditions.Unconditionally)
523539
if match_condition == MatchConditions.IfNotModified:
524540
error_map.update({412: ResourceModifiedError})
525541
if match_condition == MatchConditions.IfModified:

sdk/appconfiguration/azure-appconfiguration/azure/appconfiguration/aio/_azure_appconfiguration_client_async.py

Lines changed: 30 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -218,6 +218,8 @@ async def get_configuration_setting(
218218
label: Optional[str] = None,
219219
etag: Optional[str] = "*",
220220
match_condition: MatchConditions = MatchConditions.Unconditionally,
221+
*,
222+
accept_datetime: Optional[Union[datetime, str]] = None,
221223
**kwargs,
222224
) -> Union[None, ConfigurationSetting]:
223225

@@ -250,7 +252,6 @@ async def get_configuration_setting(
250252
key="MyKey", label="MyLabel"
251253
)
252254
"""
253-
accept_datetime = kwargs.pop("accept_datetime", None)
254255
if isinstance(accept_datetime, datetime):
255256
accept_datetime = str(accept_datetime)
256257

@@ -329,6 +330,8 @@ async def set_configuration_setting(
329330
self,
330331
configuration_setting: ConfigurationSetting,
331332
match_condition: MatchConditions = MatchConditions.Unconditionally,
333+
*,
334+
etag: Optional[str] = None,
332335
**kwargs,
333336
) -> ConfigurationSetting:
334337

@@ -341,7 +344,8 @@ async def set_configuration_setting(
341344
:type configuration_setting: ~azure.appconfiguration.ConfigurationSetting
342345
:param match_condition: The match condition to use upon the etag
343346
:type match_condition: ~azure.core.MatchConditions
344-
:keyword str etag: check if the ConfigurationSetting is changed. Set None to skip checking etag
347+
:keyword str etag: check if the ConfigurationSetting is changed. \
348+
Will use the value from param configuration_setting if not set.
345349
:return: The ConfigurationSetting returned from the service
346350
:rtype: ~azure.appconfiguration.ConfigurationSetting
347351
:raises: :class:`~azure.core.exceptions.HttpResponseError`, \
@@ -366,8 +370,6 @@ async def set_configuration_setting(
366370
)
367371
returned_config_setting = await async_client.set_configuration_setting(config_setting)
368372
"""
369-
etag = kwargs.get("etag", configuration_setting.etag)
370-
371373
key_value = configuration_setting._to_generated()
372374
custom_headers: Mapping[str, Any] = CaseInsensitiveDict(kwargs.get("headers"))
373375
error_map: Dict[int, Any] = {409: ResourceReadOnlyError}
@@ -386,7 +388,7 @@ async def set_configuration_setting(
386388
key=key_value.key, # type: ignore
387389
label=key_value.label,
388390
if_match=prep_if_match(configuration_setting.etag, match_condition),
389-
if_none_match=prep_if_none_match(etag, match_condition),
391+
if_none_match=prep_if_none_match(etag or configuration_setting.etag, match_condition),
390392
headers=custom_headers,
391393
error_map=error_map,
392394
)
@@ -396,7 +398,13 @@ async def set_configuration_setting(
396398

397399
@distributed_trace_async
398400
async def delete_configuration_setting(
399-
self, key: str, label: Optional[str] = None, **kwargs
401+
self,
402+
key: str,
403+
label: Optional[str] = None,
404+
*,
405+
etag: Optional[str] = None,
406+
match_condition: MatchConditions = MatchConditions.Unconditionally,
407+
**kwargs,
400408
) -> ConfigurationSetting:
401409
"""Delete a ConfigurationSetting if it exists
402410
@@ -426,8 +434,6 @@ async def delete_configuration_setting(
426434
key="MyKey", label="MyLabel"
427435
)
428436
"""
429-
etag = kwargs.pop("etag", None)
430-
match_condition = kwargs.pop("match_condition", MatchConditions.Unconditionally)
431437
custom_headers: Mapping[str, Any] = CaseInsensitiveDict(kwargs.get("headers"))
432438
error_map: Dict[int, Any] = {409: ResourceReadOnlyError}
433439
if match_condition == MatchConditions.IfNotModified:
@@ -453,7 +459,13 @@ async def delete_configuration_setting(
453459

454460
@distributed_trace
455461
def list_revisions(
456-
self, key_filter: Optional[str] = None, label_filter: Optional[str] = None, **kwargs
462+
self,
463+
key_filter: Optional[str] = None,
464+
label_filter: Optional[str] = None,
465+
*,
466+
accept_datetime: Optional[Union[datetime, str]] = None,
467+
fields: Optional[List[str]] = None,
468+
**kwargs,
457469
) -> AsyncItemPaged[ConfigurationSetting]:
458470

459471
"""
@@ -492,19 +504,17 @@ def list_revisions(
492504
async for item in filtered_revisions:
493505
pass # do something
494506
"""
495-
accept_datetime = kwargs.pop("accept_datetime", None)
496507
if isinstance(accept_datetime, datetime):
497508
accept_datetime = str(accept_datetime)
498-
select = kwargs.pop("fields", None)
499-
if select:
500-
select = ["locked" if x == "read_only" else x for x in select]
509+
if fields:
510+
fields = ["locked" if x == "read_only" else x for x in fields]
501511

502512
try:
503513
return self._impl.get_revisions( # type: ignore
504514
label=label_filter,
505515
key=key_filter,
506516
accept_datetime=accept_datetime,
507-
select=select,
517+
select=fields,
508518
cls=lambda objs: [ConfigurationSetting._from_generated(x) for x in objs],
509519
**kwargs,
510520
)
@@ -513,7 +523,12 @@ def list_revisions(
513523

514524
@distributed_trace_async
515525
async def set_read_only(
516-
self, configuration_setting: ConfigurationSetting, read_only: bool = True, **kwargs
526+
self,
527+
configuration_setting: ConfigurationSetting,
528+
read_only: bool = True,
529+
*,
530+
match_condition: MatchConditions = MatchConditions.Unconditionally,
531+
**kwargs,
517532
) -> ConfigurationSetting:
518533

519534
"""Set a configuration setting read only
@@ -542,7 +557,6 @@ async def set_read_only(
542557
read_only_config_setting = await client.set_read_only(config_setting, read_only=False)
543558
"""
544559
error_map: Dict[int, Any] = {}
545-
match_condition = kwargs.pop("match_condition", MatchConditions.Unconditionally)
546560
if match_condition == MatchConditions.IfNotModified:
547561
error_map.update({412: ResourceModifiedError})
548562
if match_condition == MatchConditions.IfModified:

0 commit comments

Comments
 (0)