Whole file
dynaconf/dynaconf
The author described this change as “Fix #959 cli get will exit code 1 in case of KeyError. (#960)”. It counts as a record because the check below fails on the code as it stood at 1cd1c6fcd and passes on 5ae017641, with nothing else changed between the two runs.
Projectdynaconf/dynaconf
Fix saved2023-07-13
Sharing licenceMIT · LICENSE
Change size+6 −2
What the code was meant to do, written into the code itself as a save note
Fix #959 cli get will exit code 1 in case of KeyError. (#960)
The change
| 473 | 473 | if default is not empty: | |
| 474 | 474 | result = settings.get(key, default) | |
| 475 | 475 | else: | |
| 476 | - | result = settings[key] # let the keyerror raises | |
| 476 | + | try: | |
| 477 | + | result = settings[key] | |
| 478 | + | except KeyError: | |
| 479 | + | click.echo("Key not found", nl=False, err=True) | |
| 480 | + | sys.exit(1) | |
| 477 | 481 | ||
| 478 | 482 | if unparse: | |
| 479 | 483 | result = unparse_conf_data(result) | |
| ⋯ | |||
| 596 | 600 | value = empty | |
| 597 | 601 | ||
| 598 | 602 | if value is empty: | |
| 599 | - | click.echo(click.style("Key not found", bg="red", fg="white")) | |
| 603 | + | click.secho("Key not found", bg="red", fg="white", err=True) | |
| 600 | 604 | return | |
| 601 | 605 | ||
| 602 | 606 | click.echo(format_setting(key, value)) | |
The check that tells the two apart
fail→pass·tests/test_cli.py::test_negative_get
Check file tests/test_cli.py, taken without changes from the fix and copied onto the older code, so the exact same check runs against both versions.
Origin and history
The code before it1cd1c6fcdf62f99013726c994cd7209d0f2233d6
Broken version dated2023-07-12
Moduledynaconf.cli
Units changed_list, get
Fingerprint4b7e2f0689c55e48
Checked2026-08-18 by goldset/0.1
Every field above is generated by our program. None of it is written by hand.
Other bugs found in dynaconf/dynaconf
- 2026-08-05find_the_correct_casing
- 2026-08-01get_history
- 2026-07-31fix: add __deepcopy__ to DataDict to match DataList (#1440)
- 2026-07-29normalize_kwargs
- 2026-07-29handle_metavalues
- 2026-07-29object_merge