Ask the providers for fund constituents during a sync
Fixes the gap the daily sweep found on #201 (finding 5, from cubic P1 4053196040). Part of #122.
The problem
#200 merged constituent storage, Security#look_through_weights, the constituents_fetched_at gate and the EODHD ETF_Data.Holdings mapping — and nothing ever asks for any of it.
Both importers pass include_classification: true and neither passes include_constituents::
Account::MarketDataImporter#import_security_prices(line 90)MarketDataImporter#import_security_prices(line 33)
So constituents_fetched_at stays nil for every security in production, holds_any_fund_constituents? is false for every portfolio, and the "see through funds" toggle #201 adds would never be offered to a single user. The merged feature does nothing, and would have kept doing nothing silently — there is no error, no log line, just a table that never fills.
The fix
One keyword at each of the two call sites.
It never costs two requests — which is not the same as costing nothing. The gate in import_provider_details makes one fetch_security_info call and reads metadata, classification and constituents from that one response, so the two flags never double up; that is the argument 3.1 made when it added sector and industry to a call that was already happening.
What it does cost, stated because the code comment now states it: a security that already had metadata and a classification used to skip the fetch entirely, and a nil constituents_fetched_at reopens it. So the first sync after this deploys asks once for every such security, and a security whose response keeps failing is asked again every sync — the unbounded case the gate's own comment in Security::Provided exists to bound, tracked as #212. The trade is deliberate: one pass over the existing catalogue in exchange for a feature that is otherwise inert.
A deployment without EODHD simply gets no constituents rather than an error.
Evidence
Written before the fix and watched to fail — both tests failed with Expected: ["MSFT"], Actual: [].
The tests drive each importer end to end against a stubbed provider and assert the constituents land in the table, rather than asserting the keyword was passed. That is deliberate: an unexercised code path, not a missing keyword, is what made this inert, and a signature assertion would pass even if the gate downstream refused the request.
Two mutations, both caught — removing the keyword from either importer fails its test with "so look-through stays inert".
Worth recording: both tests were silently no-ops first
Getting them to fail for the right reason took two corrections, and both are the same class of trap:
Account::MarketDataImporter#import_security_pricesopens withreturn unless Security.provider, and no securities provider is configured in the test environment. Without stubbing it the importer returns immediately and the test asserts nothing.MarketDataImporterguards onSecurity.providers.any?instead — a different predicate — so it needed its own stub.
Before those stubs, both tests were passing against an importer that did nothing, which is precisely the failure this PR exists to fix. The stubs are commented in place so the next person does not remove them and quietly restore the no-op.
Checks: full suite 9985 runs, 41679 assertions, 0 failures, 0 errors, 33 skips. bin/rubocop: 2778 files, no offenses.
Note on sequencing
This is independent of #201 and can merge first — #201 adds the UI toggle that this makes reachable. Without this, #201 ships a control that is correct and never appears.
Summary by CodeRabbit
-
Enhancements
- Security price imports now retrieve provider classifications and fund constituents together.
- Fund holdings are imported during both account-level and family-wide market data updates.
- Imported constituent data records when holdings were last retrieved.
-
Bug Fixes
- Fixed fund constituent ingestion so underlying holdings are correctly added during market data imports.