Skip to content

fix(config): use safe_substitute to prevent crashes on $ in config values (fixes #2349)#2369

Open
hanhan761 wants to merge 1 commit into
microsoft:mainfrom
hanhan761:fix-2349-safe-substitute
Open

fix(config): use safe_substitute to prevent crashes on $ in config values (fixes #2349)#2369
hanhan761 wants to merge 1 commit into
microsoft:mainfrom
hanhan761:fix-2349-safe-substitute

Conversation

@hanhan761
Copy link
Copy Markdown

Summary

Replace substitute() with safe_substitute() in config env-var parsing so that bare $ characters (e.g. regex file_pattern: ".*\\.txt$") don't crash the config loader.

Changes

  • In graphrag-common/graphrag_common/config/load_config.py, replaced Template(text).substitute(os.environ) with Template(text).safe_substitute(os.environ)
  • Removed the now-unnecessary try/except KeyError wrapper, since safe_substitute() never raises KeyError or ValueError

Issue

Fixes #2349

Verification

>>> from string import Template
>>> t = Template('.*\\.txt$')
>>> t.safe_substitute({})
'.*\\.txt$'

safe_substitute() leaves unrecognized $ patterns as literal text instead of raising ValueError.

@hanhan761 hanhan761 requested a review from a team as a code owner May 30, 2026 08:38
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Bug: string.Template.substitute() crashes on $ in config values like regex file_pattern

1 participant