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.

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

237237 self,
238238 var,
239239 default: Union[str, NoValue] = NOTSET,
240- multiline=False) -> str:
240+ multiline=False,
241+ choices=NOTSET) -> str:
241242 """
242243 :rtype: str
243244 """
244245 value = self.get_value(var, cast=str, default=default)
245246 if multiline:
246247 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+ )
247254 return value
248255
249256 def bytes(

The check that tells the two apart

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