Skip to content

fix: Declare merged_git_metadata_settings before usage#10

Merged
AbhiPrasad merged 1 commit intomainfrom
abhi-unbound-local-error-git-metadata
Feb 26, 2026
Merged

fix: Declare merged_git_metadata_settings before usage#10
AbhiPrasad merged 1 commit intomainfrom
abhi-unbound-local-error-git-metadata

Conversation

@AbhiPrasad
Copy link
Member

resolves #8

AI Summary

Fix: One-line initialization at logger.py:1642merged_git_metadata_settings = None

Bug: When repo_info is passed to braintrust.init(), the code skips the else block where merged_git_metadata_settings gets assigned (line 1646), but later references it unconditionally on line 1660. This causes an UnboundLocalError whenever base_experiment_id and base_experiment are both None (the default).

Fix behavior: Initializing to None before the if/else ensures the variable is always defined. Since None is falsy, the elif on line 1660 short-circuits correctly — skipping ancestor commit collection, which is the right behavior when the user explicitly provides repo_info.

Test: Added test_init_with_repo_info_does_not_raise in test_logger.py that calls braintrust.init(project=..., repo_info=RepoInfo(...)) and forces compute_metadata() to execute. Verified it fails with UnboundLocalError without the fix and passes with it.

@AbhiPrasad AbhiPrasad merged commit 2b0d9e2 into main Feb 26, 2026
33 checks passed
@AbhiPrasad AbhiPrasad deleted the abhi-unbound-local-error-git-metadata branch February 26, 2026 17:35
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.

Python 3.14: UnboundLocalError in compute_metadata when repo_info is provided

3 participants