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.

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

473473 if default is not empty:
474474 result = settings.get(key, default)
475475 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)
477481
478482 if unparse:
479483 result = unparse_conf_data(result)
596600 value = empty
597601
598602 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)
600604 return
601605
602606 click.echo(format_setting(key, value))

The check that tells the two apart

failpass·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