Skip to content

Commit b8392ae

Browse files
committed
Update __init__.py
1 parent df5d014 commit b8392ae

File tree

2 files changed

+7
-11
lines changed

2 files changed

+7
-11
lines changed

src/functions_framework/__init__.py

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@
1212
# See the License for the specific language governing permissions and
1313
# limitations under the License.
1414

15-
import distutils
1615
import functools
1716
import inspect
1817
import io
@@ -444,13 +443,10 @@ def _configure_app_execution_id_logging():
444443

445444

446445
def _enable_execution_id_logging():
446+
# Based on distutils.util.strtobool
447+
truthy_values = ('y', 'yes', 't', 'true', 'on', '1')
447448
env_var_value = os.environ.get("LOG_EXECUTION_ID")
448-
if not env_var_value:
449-
return False
450-
try:
451-
return bool(distutils.util.strtobool(env_var_value))
452-
except ValueError:
453-
return False
449+
return env_var_value in truthy_values
454450

455451

456452
app = LazyWSGIApp()

tests/test_execution_id.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ def test_user_function_can_retrieve_execution_id_from_header():
4646

4747

4848
def test_uncaught_exception_in_user_function_sets_execution_id(capsys, monkeypatch):
49-
monkeypatch.setenv("LOG_EXECUTION_ID", "True")
49+
monkeypatch.setenv("LOG_EXECUTION_ID", "true")
5050
source = TEST_FUNCTIONS_DIR / "execution_id" / "main.py"
5151
target = "error"
5252
app = create_app(target, source)
@@ -64,7 +64,7 @@ def test_uncaught_exception_in_user_function_sets_execution_id(capsys, monkeypat
6464

6565

6666
def test_print_from_user_function_sets_execution_id(capsys, monkeypatch):
67-
monkeypatch.setenv("LOG_EXECUTION_ID", "True")
67+
monkeypatch.setenv("LOG_EXECUTION_ID", "true")
6868
source = TEST_FUNCTIONS_DIR / "execution_id" / "main.py"
6969
target = "print_message"
7070
app = create_app(target, source)
@@ -83,7 +83,7 @@ def test_print_from_user_function_sets_execution_id(capsys, monkeypatch):
8383

8484

8585
def test_log_from_user_function_sets_execution_id(capsys, monkeypatch):
86-
monkeypatch.setenv("LOG_EXECUTION_ID", "True")
86+
monkeypatch.setenv("LOG_EXECUTION_ID", "true")
8787
source = TEST_FUNCTIONS_DIR / "execution_id" / "main.py"
8888
target = "log_message"
8989
app = create_app(target, source)
@@ -321,7 +321,7 @@ def test_log_handler_omits_empty_execution_context(monkeypatch, capsys):
321321

322322
@pytest.mark.asyncio
323323
async def test_maintains_execution_id_for_concurrent_requests(monkeypatch, capsys):
324-
monkeypatch.setenv("LOG_EXECUTION_ID", "True")
324+
monkeypatch.setenv("LOG_EXECUTION_ID", "true")
325325
monkeypatch.setattr(
326326
execution_id,
327327
"_generate_execution_id",

0 commit comments

Comments
 (0)