Skip to content

Cache design flaw in get_financial_metrics prevents fetching newer data #254

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
VincentChen525 opened this issue Apr 27, 2025 · 0 comments
Labels
bug Something isn't working

Comments

@VincentChen525
Copy link

VincentChen525 commented Apr 27, 2025

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

  1. Query financial metrics for ticker "AAPL" with end_date="2023-12-31"
  2. 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:

if cached_data := _cache.get_financial_metrics(ticker):
    # Get most recent report in cache
    most_recent = max(metric["report_period"] for metric in cached_data)
    
    # If we have recent enough data, filter and return
    if most_recent >= end_date or datetime.date.fromisoformat(most_recent) > datetime.date.today() - datetime.timedelta(days=90):
        filtered_data = [FinancialMetrics(**metric) for metric in cached_data if metric["report_period"] <= end_date]
        filtered_data.sort(key=lambda x: x.report_period, reverse=True)
        if filtered_data:
            return filtered_data[:limit]

This ensures we only use cached data if it contains sufficiently recent information.

@VincentChen525 VincentChen525 added the bug Something isn't working label Apr 27, 2025
@VincentChen525 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
LohitakshaRohila added a commit to LohitakshaRohila/ai-hedge-fund that referenced this issue May 17, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant