fix: parse UNSTRUCTURED_INCLUDE_DEBUG_METADATA env var as a boolean#4399
Open
chuenchen309 wants to merge 1 commit into
Unstructured-IO:mainUnstructured-IO/unstructured:mainfrom
chuenchen309:fix/debug-metadata-env-bool-parsingchuenchen309/unstructured:fix/debug-metadata-env-bool-parsingCopy head branch name to clipboard
Open
fix: parse UNSTRUCTURED_INCLUDE_DEBUG_METADATA env var as a boolean#4399chuenchen309 wants to merge 1 commit intoUnstructured-IO:mainUnstructured-IO/unstructured:mainfrom chuenchen309:fix/debug-metadata-env-bool-parsingchuenchen309/unstructured:fix/debug-metadata-env-bool-parsingCopy head branch name to clipboard
chuenchen309 wants to merge 1 commit into
Unstructured-IO:mainUnstructured-IO/unstructured:mainfrom
chuenchen309:fix/debug-metadata-env-bool-parsingchuenchen309/unstructured:fix/debug-metadata-env-bool-parsingCopy head branch name to clipboard
Conversation
Contributor
There was a problem hiding this comment.
No issues found across 4 files
Shadow auto-approve: would auto-approve. Fixes a bug in boolean env var parsing that caused setting the variable to 'false' to enable debug metadata. The change is small, test-covered, and follows existing patterns.
Re-trigger cubic
os.getenv("UNSTRUCTURED_INCLUDE_DEBUG_METADATA", False) treats any
explicitly-set string as truthy in Python, so setting the variable to
"false" or "0" to explicitly disable debug metadata actually enables it
-- the opposite of the caller's intent.
Parse the value the same way ENVConfig._get_bool already does elsewhere
in this codebase: "true"/"1"/"t" (case-insensitive) is True, everything
else (including unset) is False.
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
chuenchen309
force-pushed
the
fix/debug-metadata-env-bool-parsing
branch
from
July 15, 2026 22:04
30a1509 to
a2b0bf8
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
os.getenvalways returns a string when the variable is set, and any non-empty string is truthy in Python — so setting the variable to explicitly disable debug metadata (UNSTRUCTURED_INCLUDE_DEBUG_METADATA=falseor=0) actually enables it, the opposite of the operator's intent. Only leaving the variable completely unset gives the intendedFalse.The codebase already has a correct helper for exactly this pattern elsewhere:
Fix
Parse the raw env var value the same way
ENVConfig._get_booldoes:"true"/"1"/"t"(case-insensitive) isTrue, everything else (including unset) isFalse.Testing
Added
test_include_debug_metadata_parses_bool_string, parametrized over"true"/"1"/"t"(expectTrue) and"false"/"0"/"no"(expectFalse), reloading theconstantsmodule aftermonkeypatch.setenvto pick up the change. Confirmed it fails against the pre-fix code (e.g.assert 'false' is False— got the string'false', not the bool) and passes after.pytest test_unstructured/partition/utils/test_config.py— 11/11 passed.ruff check/ruff format --checkclean.CHANGELOG.mdand bumped__version__.pyto0.25.1per the contributing checklist. Note: two other open PRs (fix: strip leading UTF-8 BOM before JSON content-shape detection #4397, fix: catch UnicodeDecodeError in _is_json to avoid crashing detect_filetype() #4398) from this same debut day independently propose the same0.25.1bump from the same0.25.0base — whichever merges first "claims"0.25.1; the others (including this one, if it lands last) will need a quick rebase to the next patch version. Flagging so it's not a surprise at merge time.AI disclosure
Developed with AI assistance (Claude Code), which located the boolean-parsing bug while auditing environment-variable handling across the codebase and noticed the existing correct pattern in
ENVConfig._get_boolthat this constant didn't follow. I reviewed the diff, independently reproduced the bug and the fix by executing both, and ran the tests/linters myself before opening this PR.