You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
There's a critical caching issue in the get_financial_metrics function that prevents users from getting the most recent financial data when they've previously queried older data for the same ticker.
Steps to Reproduce
Query financial metrics for ticker "AAPL" with end_date="2023-12-31"
Later query the same ticker with a more recent date (e.g., end_date="2024-12-31")
Current Behavior
When step 2 is executed, the function finds cached data from the earlier query and filters by the new end_date. Since the older data's report_period is before the new end_date, the function returns only the old cached data without making an API call to fetch newer reports.
Expected Behavior
When querying with a newer end_date, the function should check if the cached data contains recent enough entries, and if not, make an API call to fetch the most recent data.
Root Cause
The caching mechanism only checks for the existence of data for a ticker without validating whether that data covers the requested time period adequately. The filter only excludes data that is too recent, but doesn't identify when data is too old or incomplete.
Proposed Solution
Modify the cache lookup to also check the most recent report_period in the cached data:
ifcached_data:=_cache.get_financial_metrics(ticker):
# Get most recent report in cachemost_recent=max(metric["report_period"] formetricincached_data)
# If we have recent enough data, filter and returnifmost_recent>=end_dateordatetime.date.fromisoformat(most_recent) >datetime.date.today() -datetime.timedelta(days=90):
filtered_data= [FinancialMetrics(**metric) formetricincached_dataifmetric["report_period"] <=end_date]
filtered_data.sort(key=lambdax: x.report_period, reverse=True)
iffiltered_data:
returnfiltered_data[:limit]
This ensures we only use cached data if it contains sufficiently recent information.
The text was updated successfully, but these errors were encountered:
VincentChen525
changed the title
Potential caching issue in get_financial_metrics function: period parameter not included in cache key
Cache design flaw in get_financial_metrics prevents fetching newer data
Apr 27, 2025
Uh oh!
There was an error while loading. Please reload this page.
Description
There's a critical caching issue in the
get_financial_metrics
function that prevents users from getting the most recent financial data when they've previously queried older data for the same ticker.Steps to Reproduce
end_date="2023-12-31"
end_date="2024-12-31"
)Current Behavior
When step 2 is executed, the function finds cached data from the earlier query and filters by the new end_date. Since the older data's
report_period
is before the new end_date, the function returns only the old cached data without making an API call to fetch newer reports.Expected Behavior
When querying with a newer end_date, the function should check if the cached data contains recent enough entries, and if not, make an API call to fetch the most recent data.
Root Cause
The caching mechanism only checks for the existence of data for a ticker without validating whether that data covers the requested time period adequately. The filter only excludes data that is too recent, but doesn't identify when data is too old or incomplete.
Proposed Solution
Modify the cache lookup to also check the most recent
report_period
in the cached data:This ensures we only use cached data if it contains sufficiently recent information.
The text was updated successfully, but these errors were encountered: