Closed darose closed 3 months ago
Thanks for the python interface, I've just started using it and encountered the same issue using alpaca-py==0.14.0
, where Pydantic validation fails due to missing fields in the API response. I believe this problem results from Pydantic's handling of optional fields, see Pydantic v2 migration guide.
In the guide, it's mentioned that class attributes defined as Optional[date]
without a default value are considered "Required, can be None," meaning they are expected to be present in the data, albeit they can be None. However, for fields to truly be optional—where they can be omitted from the data entirely without triggering validation errors—they should be defined with a default value, e.g., ex_date: Optional[date] = None
. This change marks the fields as "Not required, can be None, and is None by default," allowing them to accommodate missing fields in the API response.
It appears that the CorporateActionAnnouncement class definition needs updating to reflect this understanding, specifically by assigning default values to optional fields. The test case appears to include all of the fields so wouldn't catch this scenario.
@DougForrest thank you for heads-up. I will handle this issue.
prev fix PR: https://github.com/alpacahq/alpaca-py/pull/426
Is there an existing issue for this?
Current Behavior
In v0.11.0 of alpaca-py when I make the following call to the API:
... I receive the following error messages in response:
Expected Behavior
The API should not display any errors, and should instead return a list of
CorporateActionAnnouncement
objects.SDK Version I encountered this issue in
v0.11.0
Steps To Reproduce
Filled out the Steps to Reproduce section?
Anything else?
No response