Whole file
joke2k/django-environ
The author described this change as “Feature/add choice parameter and raise an exception if fetched value is not within (#555)”. It counts as a record because the check below fails on the code as it stood at c4414130f and passes on 24b299e00, with nothing else changed between the two runs.
Projectjoke2k/django-environ
Fix saved2026-02-17
Sharing licenceMIT · LICENSE.txt
Change size+8 −1
What the code was meant to do, written into the code itself as a save note
Feature/add choice parameter and raise an exception if fetched value is not within (#555)
The change
| 237 | 237 | self, | |
| 238 | 238 | var, | |
| 239 | 239 | default: Union[str, NoValue] = NOTSET, | |
| 240 | - | multiline=False) -> str: | |
| 240 | + | multiline=False, | |
| 241 | + | choices=NOTSET) -> str: | |
| 241 | 242 | """ | |
| 242 | 243 | :rtype: str | |
| 243 | 244 | """ | |
| 244 | 245 | value = self.get_value(var, cast=str, default=default) | |
| 245 | 246 | if multiline: | |
| 246 | 247 | return re.sub(r'(\\r)?\\n', r'\n', value) | |
| 248 | + | if choices is not self.NOTSET: | |
| 249 | + | # if choices is provided, check that the value is in choices | |
| 250 | + | if value not in choices: | |
| 251 | + | raise ImproperlyConfigured( | |
| 252 | + | f"Invalid value: {value} not in {choices}" | |
| 253 | + | ) | |
| 247 | 254 | return value | |
| 248 | 255 | ||
| 249 | 256 | def bytes( |
The check that tells the two apart
fail→pass·tests/test_env.py::TestEnv::test_str[STR_VAR-bar-False-choices2]
Check file tests/test_env.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 itc4414130f4cf11704e9f1ea446c68074f69c0b54
Broken version dated2026-02-17
Moduleenviron.environ
Units changedEnv
Fingerprint69f0ea87c18d32f0
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 joke2k/django-environ
- 2026-02-20Fix prometheus DB scheme aliases: underscores → hyphens (#585)
- 2022-06-14Fix `environ.Path.__eq__()` to compare paths correctly
- 2021-12-13fix unquote vs unquote_plus issue
- 2021-12-09fix[db_url_config]: added postgres cluster DSN support (ie postgresql://username:password@host1:port1,host2:port2/database)
- 2021-09-01Fix db_url_config to work the same for all postgres-like schemes