diff --git a/CHANGELOG.md b/CHANGELOG.md index 5f1d11f8f6..bff8e5e25b 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -3,6 +3,7 @@ ### Fixes - **Update README.md**: readme-only changes; added a link to Unstructured Pipelines to the README. No library behavior changes. +- **`UNSTRUCTURED_INCLUDE_DEBUG_METADATA` now parses its env var value as a boolean**: previously `os.getenv("UNSTRUCTURED_INCLUDE_DEBUG_METADATA", False)` treated any explicitly-set string value (including `"false"` or `"0"`) as truthy, so setting the variable to explicitly disable debug metadata actually enabled it. Now parses the value the same way `ENVConfig._get_bool` already does elsewhere in the codebase (`"true"`/`"1"`/`"t"`, case-insensitive, is `True`; everything else, including unset, is `False`). ## 0.25.0 diff --git a/test_unstructured/partition/utils/test_config.py b/test_unstructured/partition/utils/test_config.py index 48f57a5395..e8b15f7a3f 100644 --- a/test_unstructured/partition/utils/test_config.py +++ b/test_unstructured/partition/utils/test_config.py @@ -1,3 +1,4 @@ +import importlib import shutil import tempfile from pathlib import Path @@ -5,6 +6,41 @@ import pytest +@pytest.mark.parametrize( + ("env_value", "expected"), + [ + ("true", True), + ("1", True), + ("t", True), + ("false", False), + ("0", False), + ("no", False), + ], +) +def test_include_debug_metadata_parses_bool_string(monkeypatch, env_value, expected): + from unstructured.partition.utils import constants + + monkeypatch.setenv("UNSTRUCTURED_INCLUDE_DEBUG_METADATA", env_value) + try: + importlib.reload(constants) + assert constants.UNSTRUCTURED_INCLUDE_DEBUG_METADATA is expected + finally: + monkeypatch.undo() + importlib.reload(constants) + + +def test_include_debug_metadata_defaults_to_false_when_unset(monkeypatch): + from unstructured.partition.utils import constants + + monkeypatch.delenv("UNSTRUCTURED_INCLUDE_DEBUG_METADATA", raising=False) + try: + importlib.reload(constants) + assert constants.UNSTRUCTURED_INCLUDE_DEBUG_METADATA is False + finally: + monkeypatch.undo() + importlib.reload(constants) + + def test_default_config(): from unstructured.partition.utils.config import env_config diff --git a/unstructured/partition/utils/constants.py b/unstructured/partition/utils/constants.py index c5cdcfea47..0e9f7dc614 100644 --- a/unstructured/partition/utils/constants.py +++ b/unstructured/partition/utils/constants.py @@ -50,7 +50,13 @@ class PartitionStrategy: "unstructured.partition.utils.speech_to_text.whisper_stt", ).split(",") -UNSTRUCTURED_INCLUDE_DEBUG_METADATA = os.getenv("UNSTRUCTURED_INCLUDE_DEBUG_METADATA", False) +UNSTRUCTURED_INCLUDE_DEBUG_METADATA = os.getenv( + "UNSTRUCTURED_INCLUDE_DEBUG_METADATA", "" +).lower() in ( + "true", + "1", + "t", +) # this field is defined by unstructured_pytesseract TESSERACT_TEXT_HEIGHT = "height"