Fix get_available_budget validation bug#8
Conversation
There was a problem hiding this comment.
Pull Request Overview
This PR fixes a validation bug in the get_available_budget functionality by adding proper type conversion for currency_id fields. The issue appears to be that currency_id values are sometimes received as integers but need to be strings for proper validation.
- Adds a Pydantic field validator to convert integer
currency_idvalues to strings - Imports the necessary
field_validatorfrom Pydantic
Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.
| @field_validator('currency_id', mode='before') | ||
| @classmethod | ||
| def convert_currency_id_to_str(cls, v): | ||
| """Convert currency_id from int to str if needed.""" |
There was a problem hiding this comment.
[nitpick] The docstring should be more descriptive about why this conversion is necessary. Consider adding context about the validation bug being fixed and when this conversion is needed (e.g., "Convert currency_id from int to str to fix validation issues when API responses contain integer currency_id values instead of expected string format").
| @field_validator('currency_id', mode='before') | |
| @classmethod | |
| def convert_currency_id_to_str(cls, v): | |
| """Convert currency_id from int to str if needed.""" | |
| """ | |
| Convert currency_id from int to str to fix validation issues. | |
| This conversion is necessary because some API responses may return | |
| currency_id as an integer instead of the expected string format. | |
| Without this conversion, Pydantic validation may fail or produce | |
| unexpected results. This validator ensures that currency_id is always | |
| a string, as required by the model. | |
| """ |
No description provided.