From b212be84a3f00d53269e7e3b5c0ced8002486000 Mon Sep 17 00:00:00 2001 From: Maxim Harder Date: Fri, 15 Nov 2024 13:22:37 +0100 Subject: [PATCH] Fixed empty values If you use empty values in your env files, e.g. `DB_PORT=` and cast it in call into int or float, so you will get an error: ``` ValueError: invalid literal for int() with base 10: '' ``` I just fixed that for me with this universal solution. It works not only on int or float --- decouple.py | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/decouple.py b/decouple.py index 9873fc9..86295fd 100644 --- a/decouple.py +++ b/decouple.py @@ -98,6 +98,12 @@ def get(self, option, default=undefined, cast=undefined): elif cast is bool: cast = self._cast_boolean + if value is None or value == '': + if not isinstance(default, Undefined): + value = default + else: + cast = self._cast_do_nothing + return cast(value) def __call__(self, *args, **kwargs):