{"record":{"id":"2ced2124d740ed32","repo":"we-promise/sure","slug":"ibkr-provider-is-not-configured","errorCode":null,"errorMessage":"IBKR provider is not configured","messagePattern":"IBKR provider is not configured","errorType":"exception","errorClass":"StandardError","httpStatus":null,"severity":"error","filePath":"app/models/ibkr_item.rb","lineNumber":37,"sourceCode":"  validates :token, presence: true, on: :create\n\n  scope :active, -> { where(scheduled_for_deletion: false) }\n  scope :syncable, -> { active.where.not(query_id: [ nil, \"\" ]).where.not(token: nil) }\n  scope :ordered, -> { order(created_at: :desc) }\n  scope :needs_update, -> { where(status: :requires_update) }\n\n  def destroy_later\n    update!(scheduled_for_deletion: true)\n    DestroyJob.perform_later(self)\n  end\n\n  def credentials_configured?\n    query_id.present? && token.present?\n  end\n\n  def import_latest_ibkr_data\n    provider = ibkr_provider\n    raise StandardError, \"IBKR provider is not configured\" unless provider\n\n    IbkrItem::Importer.new(self, ibkr_provider: provider).import\n  rescue => e\n    Rails.logger.error(\"IbkrItem #{id} - Failed to import data: #{e.message}\")\n    raise\n  end\n\n  def process_accounts\n    return [] if ibkr_accounts.empty?\n\n    linked_ibkr_accounts.includes(account_provider: :account).each_with_object([]) do |ibkr_account, results|\n      account = ibkr_account.current_account\n      next unless account\n      next if account.pending_deletion? || account.disabled?\n\n      begin\n        result = IbkrAccount::Processor.new(ibkr_account).process\n        results << { ibkr_account_id: ibkr_account.id, success: true, result: result }","sourceCodeStart":19,"sourceCodeEnd":55,"githubUrl":"https://github.com/we-promise/sure/blob/e69894adb92547273377398c15f45c979cd9416a/app/models/ibkr_item.rb#L19-L55","documentation":"IbkrItem#import_latest_ibkr_data raises StandardError('IBKR provider is not configured') when ibkr_provider returns nil. credentials_configured? (app/models/ibkr_item.rb:31) requires BOTH query_id and token to be present; the provided concern returns a nil provider when either is missing, and the import refuses to run.","triggerScenarios":"Calling import_latest_ibkr_data (directly or via a sync flow) on an IbkrItem whose query_id or token is nil/blank — an item created but never fully credentialed, or one field cleared later.","commonSituations":"Setup flows that enqueue import before credential entry; scheduled jobs for half-configured items; data copied between environments with blank credential columns.","solutions":["Set both fields: ibkr_item.update!(query_id: <Flex Query ID>, token: <IBKR token>) and retry","Guard with ibkr_item.credentials_configured? before importing; IbkrItem::Syncer#perform_sync already does this and sets status :requires_update","Prefer the syncer path and rescue Provider::IbkrFlex::ConfigurationError rather than calling import_latest_ibkr_data unguarded"],"exampleFix":"// before\nibkr_item.import_latest_ibkr_data\n\n// after\nraise ArgumentError, 'IBKR item needs query_id and token' unless ibkr_item.credentials_configured?\n\nibkr_item.import_latest_ibkr_data","handlingStrategy":"validation","validationCode":"ibkr_item.credentials_configured? # query_id.present? && token.present? — false means import will raise","typeGuard":null,"tryCatchPattern":"rescue StandardError around import_latest_ibkr_data (the method already logs 'Failed to import data: ...' with the item id before re-raising); map the 'not configured' message to a setup-required state","preventionTips":["Require both query_id and token before an IbkrItem becomes syncable","Prefer IbkrItem::Syncer, which converts missing credentials into status :requires_update + Provider::IbkrFlex::ConfigurationError","Block scheduled syncs for items lacking credentials"],"tags":["ibkr","credentials","provider-configuration","import"],"backgroundTag":"missing-credentials","analyzedSha":"e69894adb92547273377398c15f45c979cd9416a","analyzedAt":"2026-08-21T18:22:41.165Z","schemaVersion":2},"datasetVersion":"2026-08-21T23:17:16.201Z"}