Skip to content

Commit 075d283

Browse files
authored
[AppConfig] Update FeatureFlagSetting to enable parsing different id and key name. (#35769)
1 parent ee943ef commit 075d283

File tree

4 files changed

+17
-6
lines changed

4 files changed

+17
-6
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 where the `feature_id` of `FeatureFlagConfigurationSetting` will be different from `id` customer field, and may overwrite the original customer-defined value if different from the `FeatureFlagConfigurationSetting` key suffix.
1011

1112
### Other Changes
1213

sdk/appconfiguration/azure-appconfiguration/azure/appconfiguration/_models.py

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -173,10 +173,10 @@ def __init__( # pylint: disable=super-init-not-called
173173
to be considered enabled.
174174
:paramtype filters: list[dict[str, Any]] or None
175175
"""
176-
if "key" in kwargs or "value" in kwargs:
177-
raise TypeError("Unexpected keyword argument, do not provide 'key' or 'value' as a keyword-arg")
176+
if "value" in kwargs:
177+
raise TypeError("Unexpected keyword argument, do not provide 'value' as a keyword-arg")
178178
self.feature_id = feature_id
179-
self.key = self._key_prefix + self.feature_id
179+
self.key = kwargs.get("key", None) or (self._key_prefix + self.feature_id)
180180
self.label = kwargs.get("label", None)
181181
self.content_type = kwargs.get("content_type", self._feature_flag_content_type)
182182
self.last_modified = kwargs.get("last_modified", None)
@@ -235,19 +235,23 @@ def _from_generated(cls, key_value: KeyValue) -> "FeatureFlagConfigurationSettin
235235
filters = None
236236
display_name = None
237237
description = None
238+
feature_id = None
238239
try:
239240
temp = json.loads(key_value.value) # type: ignore
240241
if isinstance(temp, dict):
241242
enabled = temp.get("enabled", False)
242243
display_name = temp.get("display_name")
243244
description = temp.get("description")
245+
feature_id = temp.get("id")
246+
244247
if "conditions" in temp.keys():
245248
filters = temp["conditions"].get("client_filters")
246249
except (ValueError, json.JSONDecodeError):
247250
pass
248251

249252
return cls(
250-
feature_id=key_value.key.lstrip(".appconfig.featureflag").lstrip("/"), # type: ignore
253+
feature_id=feature_id, # type: ignore
254+
key=key_value.key,
251255
label=key_value.label,
252256
content_type=key_value.content_type,
253257
last_modified=key_value.last_modified,

sdk/appconfiguration/azure-appconfiguration/tests/test_azure_appconfiguration_client.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1171,8 +1171,6 @@ def test_monitor_configuration_settings_by_page_etag(self, appconfiguration_conn
11711171

11721172
class TestAppConfigurationClientUnitTest:
11731173
def test_type_error(self):
1174-
with pytest.raises(TypeError):
1175-
_ = FeatureFlagConfigurationSetting("blah", key="blah")
11761174
with pytest.raises(TypeError):
11771175
_ = FeatureFlagConfigurationSetting("blah", value="blah")
11781176
with pytest.raises(TypeError):

sdk/appconfiguration/azure-appconfiguration/tests/test_consistency.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -125,3 +125,11 @@ def test_feature_flag_prefix(self):
125125
key = self.get_resource_name("key")
126126
feature_flag = FeatureFlagConfigurationSetting(key, enabled=True)
127127
assert feature_flag.key.startswith(".appconfig.featureflag/")
128+
129+
def test_feature_flag_different_key_and_id(self):
130+
key = f'.appconfig.featureflag/{self.get_resource_name("key")}'
131+
feature_id = self.get_resource_name("id")
132+
feature_flag = FeatureFlagConfigurationSetting(feature_id, enabled=True, key=key)
133+
134+
assert feature_flag.feature_id == feature_id
135+
assert feature_flag.key == key

0 commit comments

Comments
 (0)