{"record":{"id":"ab340de1c0faba89","repo":"we-promise/sure","slug":"invalid-import-record","errorCode":"invalid_import_record","errorMessage":"#{record_type} has invalid #{field}: #{value.inspect}","messagePattern":"#(.+?) has invalid #(.+?): #(.+?)","errorType":"validation","errorClass":"Family::DataImporter::InvalidRecordError","httpStatus":null,"severity":"error","filePath":"app/models/family/data_importer.rb","lineNumber":242,"sourceCode":"      increment_summary(record_type, :skipped)\n      nil\n    end\n\n    def require_source_id!(record_type, source_id)\n      return if source_id.present? || !@strict_references\n\n      increment_summary(record_type, :failed)\n      raise MissingReferenceError.new(\n        record_type: record_type,\n        source_type: record_type,\n        source_id: \"(blank)\"\n      )\n    end\n\n    def invalid_record!(record_type, field, value)\n      if @strict_references\n        increment_summary(record_type, :failed)\n        raise InvalidRecordError.new(record_type: record_type, field: field, value: value)\n      end\n\n      increment_summary(record_type, :skipped)\n      nil\n    end\n\n    def session_entry_source\n      return unless @import_session\n\n      \"sure_import_session:#{@import_session.id}\"\n    end\n\n    def session_entry_external_id(record_type, source_id)\n      return if @import_session.blank? || source_id.blank?\n\n      \"#{record_type}:#{source_id}\"\n    end\n","sourceCodeStart":224,"sourceCodeEnd":260,"githubUrl":"https://github.com/we-promise/sure/blob/e69894adb92547273377398c15f45c979cd9416a/app/models/family/data_importer.rb#L224-L260","documentation":"Provider::YahooFinance::AuthenticationError raised in fetch_authenticated_chart when Yahoo returns chart.error.code == 'Unauthorized' twice: once initially, and again after the provider cleared its crumb cache, fetched a fresh cookie+crumb, and retried the same chart request. Yahoo's v8 endpoints require a valid A1/A3 cookie plus a crumb query parameter; when both attempts are rejected, the credentials context (cookie) itself is being refused, not just a stale crumb.","triggerScenarios":"Repeated chart fetches from a rate-limited or flagged IP where Yahoo invalidates cookies immediately; Yahoo-side A/B changes to the consent/crumb flow making freshly fetched cookies unusable; clock-skewed requests invalidating the session; the fc.yahoo.com cookie handoff returning a consent-redirect cookie instead of the auth cookie.","commonSituations":"Bulk sync jobs hammering Yahoo from a datacenter IP; after Yahoo changes its anti-bot flow (historically frequent); local dev behind VPN egress shared with abusers; running many provider instances with a shared cache serving poisoned crumbs.","solutions":["Back off and retry later — most double-unauthorized failures are IP-reputation rate limiting","Clear the Rails.cache crumb entries (clear_crumb_cache) so a fresh cookie/crumb pair is fetched on next call","Reduce request frequency (throttle_request settings) to stay under Yahoo's tolerance","Route via a different egress IP or residential proxy for server deployments","If persistent, switch the affected lookups to a configured alternative provider (Tiingo/EODHD)"],"exampleFix":"# before\nprices = provider.fetch_security_prices(symbol: s, start_date: a, end_date: b)\n\n# after\nbegin\n  prices = provider.fetch_security_prices(symbol: s, start_date: a, end_date: b)\nrescue Provider::YahooFinance::AuthenticationError => e\n  Rails.cache.delete_matched(\"yahoo_crumb*\") if e.message.include?(\"crumb refresh\")\n  sleep 60\n  retry if (attempts += 1) < 3\n  raise\nend","handlingStrategy":"retry","validationCode":null,"typeGuard":null,"tryCatchPattern":"attempts = 0\nbegin\n  attempts += 1\n  data = provider.fetch_security_prices(symbol: s, start_date: a, end_date: b)\nrescue Provider::YahooFinance::AuthenticationError => e\n  raise unless e.message.include?(\"crumb refresh\") && attempts < 3\n  sleep(60 * attempts) # back off; IP-reputation limiting usually clears\n  retry\nend","preventionTips":["Honor throttle_request spacing to keep IPs off Yahoo's blocklist","Cache crumbs/cookies for their full TTL instead of re-bootstrapping per request","Deploy egress via stable, reputable IPs for scheduled jobs","Have a fallback securities provider configured for sustained auth outages"],"tags":["yahoo-finance","authentication","crumb","cookie","rate-limit"],"backgroundTag":"api-authentication-failed","analyzedSha":"e69894adb92547273377398c15f45c979cd9416a","analyzedAt":"2026-08-21T18:22:41.165Z","schemaVersion":2},"datasetVersion":"2026-08-21T23:17:16.201Z"}