Change8
Error1 reports

Fix UnboundLocalError

in Pydantic Settings

Solution

The UnboundLocalError usually occurs when a variable is referenced before it's assigned a value within a specific scope, often inside a conditional block. Ensure that the variable (e.g., 'field_key') is assigned a value before being used, even if it's a default value outside the conditional. Initialize the variable at the beginning of the function/block, guaranteeing it always has a defined value.

Timeline

First reported:Jun 23, 2025
Last reported:Jun 23, 2025

Need More Help?

View the full changelog and migration guides for Pydantic Settings

View Pydantic Settings Changelog