we-promise/sure · error · StandardError
Sophtron provider is not configured
Error message
Sophtron provider is not configured
What it means
SophtronItem#import_latest_sophtron_data first builds a provider via sophtron_provider; when that returns nil (user_id or access_key missing on the record) it raises a plain StandardError before any API call, after logging that the Sophtron provider is not configured. The rescue block re-logs and re-raises, so sync jobs see the original error.
Source
Thrown at app/models/sophtron_item.rb:78
end
# Imports the latest account and transaction data from Sophtron.
#
# This method fetches all accounts and transactions from the Sophtron API
# and updates the local database accordingly. It will:
# - Fetch all accounts associated with the Sophtron connection
# - Create new SophtronAccount records for newly discovered accounts
# - Update existing linked accounts with latest data
# - Fetch and store transactions for all linked accounts
#
# @return [Hash] Import results with counts of accounts and transactions imported
# @raise [StandardError] if the Sophtron provider is not configured
# @raise [Provider::Sophtron::Error] if the Sophtron API returns an error
def import_latest_sophtron_data(sync: nil)
provider = sophtron_provider
unless provider
Rails.logger.error "SophtronItem #{id} - Cannot import: Sophtron provider is not configured (missing API key)"
raise StandardError.new("Sophtron provider is not configured")
end
SophtronItem::Importer.new(self, sophtron_provider: provider, sync: sync).import
rescue => e
Rails.logger.error "SophtronItem #{id} - Failed to import data: #{e.message}"
raise
end
def linked_visible_sophtron_accounts
sophtron_accounts.joins(:account).merge(Account.visible)
end
def automatic_sync_sophtron_accounts
return linked_visible_sophtron_accounts.none if manual_sync?
linked_visible_sophtron_accounts.automatic_sync
end
View on GitHub (pinned to e69894adb9)
Solutions
- Ensure the SophtronItem has both user_id and access_key set before scheduling syncs (validate presence beyond just on: :create)
- Verify ACTIVE_RECORD_ENCRYPTION_PRIMARY_KEY/DETERIVATION_SALT/DETERMINISTIC_KEY match the values used when the credentials were stored
- Re-enter the credentials through the settings UI (which re-encrypts with current keys)
- Guard the scheduler: skip SophtronItems where sophtron_provider is nil and surface them in an 'needs setup' list instead of raising
Example fix
# before
SophtronItem.syncable.find_each(&:import_latest_sophtron_data)
# after
SophtronItem.syncable.find_each do |item|
unless item.sophtron_provider
item.update!(status: :requires_update)
next
end
item.import_latest_sophtron_data
end Defensive patterns
Strategy: validation
Validate before calling
raise ArgumentError, "SophtronItem #{item.id} lacks credentials" if item.user_id.blank? || item.access_key.blank?
item.import_latest_sophtron_data(sync: sync) Type guard
def sophtron_item_configured?(item) item.user_id.present? && item.access_key.present? && item.sophtron_provider.present? end
Try / catch
begin item.import_latest_sophtron_data rescue StandardError => e raise unless e.message == "Sophtron provider is not configured" item.update!(status: :requires_update) NotifyUserCredentialsMissingJob.perform_later(item) end
Prevention
- Validate user_id/access_key presence on every save, not only on: :create
- Keep ACTIVE_RECORD_ENCRYPTION_* values identical across all servers that read these columns
- Smoke-test one import immediately after credential entry so misconfig surfaces at setup time
- Exclude unconfigured items from the sync scheduler's query
When it happens
Trigger: Enqueueing an import/sync for a SophtronItem whose user_id or access_key attribute is blank; records created before credentials were saved; encrypted attributes reading as nil because ACTIVE_RECORD_ENCRYPTION_* keys are missing or rotated since the values were written (encryption_ready? was false at write, true at read, or key mismatch).
Common situations: Deployments where ActiveRecord Encryption env vars were added or changed after SophtronItems already existed; sync scheduler picking up half-onboarded items; staging copies of production data where the deterministic key differs, so ciphertexts fail to decrypt to nil.
Related errors
- Trading 212 API key is missing.
- {result.error}
- {e.record.errors.full_messages.to_sentence.presence || e.mes
- request_failed
- invalid_certificate
AI-assisted analysis of we-promise/sure@e69894adb9 (2026-08-21).
Data as JSON: /api/errors/8b390f3a94f122eb.
Report an issue: GitHub.