Skip to content

Conversation

@sjhddh
Copy link

@sjhddh sjhddh commented Jan 25, 2026

Summary

Fix a bug in FinnHubUtils.get_basic_financials() that causes a RuntimeError when selected_columns is provided.

The Bug

The original code modified a dictionary while iterating over its keys:

for k in output_dict.keys():
    if selected_columns and k not in selected_columns:
        output_dict.pop(k)  # RuntimeError: dictionary changed size during iteration

The Fix

Replace the problematic loop with a dict comprehension that creates a new filtered dictionary:

if selected_columns:
    output_dict = {k: v for k, v in output_dict.items() if k in selected_columns}

Test plan

  • Verify the fix compiles without syntax errors
  • Test FinnHubUtils.get_basic_financials("AAPL", selected_columns=["eps", "pe"]) no longer crashes

The previous code modified output_dict while iterating over its keys,
which raises RuntimeError: dictionary changed size during iteration.

Replace the problematic loop with a dict comprehension that creates
a new filtered dictionary.
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.

1 participant