Commit 7400852
Ensure reset of feature flags and constants after config deployment (#871)
Resolves #872
This pull request introduces a robust and safer mechanism for handling
feature flag and constant overrides during configuration-based
deployments. The main improvement is the replacement of the previous
global override function with a context manager, ensuring that any
changes to feature flags and constants are always reverted after
deployment, even if errors occur. This prevents state leakage between
deployments and improves reliability. The pull request also updates
validation logic, enhances logging, and adds comprehensive tests to
verify correct override and restoration behavior.
Key changes include:
**Override Mechanism Improvements**
- Replaced the global `apply_config_overrides` function with a
`config_overrides_scope` context manager in
`src/fabric_cicd/_common/_config_utils.py`. This ensures that feature
flags and constants are overridden only for the duration of the
deployment and are always restored to their original values afterward,
even if exceptions occur.
[[1]](diffhunk://#diff-a595a996e85e1b2ab0a30945c022432c66c2c63fdd87c97030327c412c713485L150-R197)
[[2]](diffhunk://#diff-a8555a82747092e8d1f2ee36f31c947b4e5a264ed6c6d8de48d8daf850372704L15-R15)
[[3]](diffhunk://#diff-a8555a82747092e8d1f2ee36f31c947b4e5a264ed6c6d8de48d8daf850372704L408-R408)
- Updated all usages and tests to use the new context manager, removing
references to the old function.
[[1]](diffhunk://#diff-591b837760640c6d5c7b21d70575e6a262d56881f9ff3f993dbf10064c61d468L12-R14)
[[2]](diffhunk://#diff-591b837760640c6d5c7b21d70575e6a262d56881f9ff3f993dbf10064c61d468L375-R531)
**Validation and Logging Enhancements**
- Improved validation logic for the `features` and `constants` sections,
including more granular checks for environment-specific mappings and
individual constant keys.
[[1]](diffhunk://#diff-2b2dbdc5a0a864161ffbaf5211918409f6b2a5ea15a9e23d17ff803e6f9b2834L347-R347)
[[2]](diffhunk://#diff-2b2dbdc5a0a864161ffbaf5211918409f6b2a5ea15a9e23d17ff803e6f9b2834L356-R365)
[[3]](diffhunk://#diff-2b2dbdc5a0a864161ffbaf5211918409f6b2a5ea15a9e23d17ff803e6f9b2834L1012-R1047)
- Changed the logging level for skipped `features` and `constants` to
warnings instead of debug, making potential misconfigurations more
visible.
[[1]](diffhunk://#diff-1482256f9dd419ccd2b7281c95d3b1fa902a4af31630ad0e9dbca891241d5f2fL305-R306)
[[2]](diffhunk://#diff-2b2dbdc5a0a864161ffbaf5211918409f6b2a5ea15a9e23d17ff803e6f9b2834L1084-L1097)
**Testing Improvements**
- Added extensive tests to verify that feature flags and constants are
correctly overridden within the context and always restored after,
including when exceptions are raised. Tests also check that user-set
values are preserved and that environment-specific overrides work as
intended.
**Documentation**
- Updated documentation to reflect the new override behavior and logging
changes for `features` and `constants`.
**Bug Fix**
- Fixes issue #872: Ensures that override behavior for feature flags and
constants in config deployment is correct and state-safe.
(.changes/unreleased/fixed-20260311-110454.yaml)
---------
Co-authored-by: Shira Sassoon <shirasassoon@microsoft.com>1 parent 01cce8b commit 7400852
File tree
7 files changed
+740
-384
lines changed- .changes/unreleased
- docs/how_to
- src/fabric_cicd
- _common
- tests
7 files changed
+740
-384
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
302 | 302 | | |
303 | 303 | | |
304 | 304 | | |
305 | | - | |
306 | | - | |
| 305 | + | |
| 306 | + | |
307 | 307 | | |
308 | 308 | | |
309 | 309 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
3 | 3 | | |
4 | 4 | | |
5 | 5 | | |
| 6 | + | |
6 | 7 | | |
| 8 | + | |
7 | 9 | | |
8 | 10 | | |
9 | 11 | | |
| |||
147 | 149 | | |
148 | 150 | | |
149 | 151 | | |
150 | | - | |
151 | | - | |
| 152 | + | |
| 153 | + | |
| 154 | + | |
| 155 | + | |
| 156 | + | |
| 157 | + | |
| 158 | + | |
| 159 | + | |
152 | 160 | | |
153 | 161 | | |
154 | 162 | | |
155 | 163 | | |
156 | 164 | | |
157 | | - | |
158 | | - | |
159 | | - | |
160 | | - | |
161 | | - | |
162 | | - | |
163 | | - | |
164 | | - | |
165 | | - | |
166 | | - | |
167 | | - | |
168 | | - | |
169 | | - | |
170 | | - | |
171 | | - | |
172 | | - | |
173 | | - | |
174 | | - | |
175 | | - | |
176 | | - | |
| 165 | + | |
| 166 | + | |
| 167 | + | |
| 168 | + | |
| 169 | + | |
| 170 | + | |
| 171 | + | |
| 172 | + | |
| 173 | + | |
| 174 | + | |
| 175 | + | |
| 176 | + | |
| 177 | + | |
| 178 | + | |
| 179 | + | |
| 180 | + | |
| 181 | + | |
| 182 | + | |
| 183 | + | |
| 184 | + | |
| 185 | + | |
| 186 | + | |
| 187 | + | |
| 188 | + | |
| 189 | + | |
| 190 | + | |
| 191 | + | |
| 192 | + | |
| 193 | + | |
| 194 | + | |
| 195 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
344 | 344 | | |
345 | 345 | | |
346 | 346 | | |
347 | | - | |
| 347 | + | |
348 | 348 | | |
349 | 349 | | |
350 | 350 | | |
| |||
353 | 353 | | |
354 | 354 | | |
355 | 355 | | |
356 | | - | |
357 | | - | |
| 356 | + | |
| 357 | + | |
| 358 | + | |
| 359 | + | |
| 360 | + | |
| 361 | + | |
| 362 | + | |
| 363 | + | |
| 364 | + | |
| 365 | + | |
358 | 366 | | |
359 | 367 | | |
360 | 368 | | |
| |||
593 | 601 | | |
594 | 602 | | |
595 | 603 | | |
596 | | - | |
597 | 604 | | |
| 605 | + | |
598 | 606 | | |
599 | 607 | | |
600 | 608 | | |
| |||
652 | 660 | | |
653 | 661 | | |
654 | 662 | | |
655 | | - | |
656 | | - | |
657 | 663 | | |
658 | 664 | | |
659 | 665 | | |
660 | | - | |
661 | | - | |
662 | 666 | | |
663 | 667 | | |
664 | 668 | | |
| |||
975 | 979 | | |
976 | 980 | | |
977 | 981 | | |
978 | | - | |
979 | | - | |
980 | | - | |
981 | | - | |
982 | | - | |
983 | 982 | | |
984 | 983 | | |
985 | 984 | | |
| |||
1009 | 1008 | | |
1010 | 1009 | | |
1011 | 1010 | | |
1012 | | - | |
1013 | | - | |
1014 | | - | |
1015 | | - | |
1016 | | - | |
1017 | | - | |
1018 | | - | |
1019 | | - | |
1020 | | - | |
1021 | | - | |
1022 | | - | |
1023 | | - | |
1024 | | - | |
1025 | | - | |
1026 | | - | |
1027 | | - | |
1028 | | - | |
1029 | | - | |
1030 | | - | |
1031 | | - | |
1032 | | - | |
| 1011 | + | |
| 1012 | + | |
1033 | 1013 | | |
1034 | 1014 | | |
1035 | | - | |
| 1015 | + | |
1036 | 1016 | | |
1037 | 1017 | | |
1038 | 1018 | | |
1039 | 1019 | | |
1040 | 1020 | | |
1041 | 1021 | | |
1042 | | - | |
| 1022 | + | |
1043 | 1023 | | |
1044 | | - | |
1045 | 1024 | | |
1046 | | - | |
1047 | | - | |
1048 | | - | |
1049 | | - | |
1050 | | - | |
1051 | | - | |
1052 | | - | |
1053 | | - | |
1054 | | - | |
| 1025 | + | |
| 1026 | + | |
| 1027 | + | |
| 1028 | + | |
| 1029 | + | |
| 1030 | + | |
| 1031 | + | |
| 1032 | + | |
| 1033 | + | |
| 1034 | + | |
| 1035 | + | |
| 1036 | + | |
| 1037 | + | |
| 1038 | + | |
| 1039 | + | |
| 1040 | + | |
| 1041 | + | |
| 1042 | + | |
| 1043 | + | |
| 1044 | + | |
| 1045 | + | |
| 1046 | + | |
| 1047 | + | |
| 1048 | + | |
| 1049 | + | |
1055 | 1050 | | |
1056 | 1051 | | |
1057 | 1052 | | |
| |||
1081 | 1076 | | |
1082 | 1077 | | |
1083 | 1078 | | |
1084 | | - | |
1085 | | - | |
1086 | | - | |
| 1079 | + | |
| 1080 | + | |
| 1081 | + | |
1087 | 1082 | | |
1088 | 1083 | | |
1089 | 1084 | | |
1090 | | - | |
1091 | | - | |
1092 | | - | |
1093 | | - | |
1094 | | - | |
1095 | | - | |
1096 | | - | |
1097 | | - | |
1098 | 1085 | | |
1099 | 1086 | | |
1100 | 1087 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
12 | 12 | | |
13 | 13 | | |
14 | 14 | | |
15 | | - | |
| 15 | + | |
16 | 16 | | |
17 | 17 | | |
18 | 18 | | |
| |||
405 | 405 | | |
406 | 406 | | |
407 | 407 | | |
408 | | - | |
409 | | - | |
410 | | - | |
411 | | - | |
412 | | - | |
413 | | - | |
414 | | - | |
415 | | - | |
416 | | - | |
417 | | - | |
418 | | - | |
419 | | - | |
420 | | - | |
421 | | - | |
422 | | - | |
423 | | - | |
424 | | - | |
425 | | - | |
426 | | - | |
427 | | - | |
428 | | - | |
| 408 | + | |
| 409 | + | |
| 410 | + | |
| 411 | + | |
| 412 | + | |
| 413 | + | |
| 414 | + | |
| 415 | + | |
| 416 | + | |
| 417 | + | |
429 | 418 | | |
430 | | - | |
431 | | - | |
432 | | - | |
433 | | - | |
434 | | - | |
435 | | - | |
436 | | - | |
437 | | - | |
| 419 | + | |
| 420 | + | |
| 421 | + | |
| 422 | + | |
| 423 | + | |
| 424 | + | |
| 425 | + | |
| 426 | + | |
| 427 | + | |
| 428 | + | |
| 429 | + | |
| 430 | + | |
| 431 | + | |
| 432 | + | |
| 433 | + | |
| 434 | + | |
| 435 | + | |
| 436 | + | |
| 437 | + | |
| 438 | + | |
| 439 | + | |
| 440 | + | |
| 441 | + | |
| 442 | + | |
| 443 | + | |
| 444 | + | |
438 | 445 | | |
439 | | - | |
440 | | - | |
441 | | - | |
442 | | - | |
443 | | - | |
444 | | - | |
445 | | - | |
446 | | - | |
0 commit comments