{"record":{"id":"de1e2f1a7d0393bb","repo":"we-promise/sure","slug":"record-not-found-de1e2f","errorCode":"record_not_found","errorMessage":"The requested resource was not found","messagePattern":"The requested resource was not found","errorType":"http","errorClass":"ActiveRecord::RecordNotFound","httpStatus":404,"severity":"error","filePath":"app/models/import/preflight.rb","lineNumber":175,"sourceCode":"            filename: filename,\n            content_type: content_type,\n            content: content,\n            parsed_rows_count: parsed_rows_count,\n            csv_headers: csv_headers,\n            missing_required_headers: missing_required_headers,\n            errors: errors,\n            warnings: warnings\n          )\n        }\n      )\n    end\n\n    def import_config_params\n      params.slice(*CONFIG_PARAM_KEYS)\n    end\n\n    def preflight_account\n      raise ActiveRecord::RecordNotFound unless Api::V1::BaseController.valid_uuid?(params[:account_id])\n\n      family.accounts.find(params[:account_id])\n    end\n\n    def csv_upload_attributes\n      if params[:file].present?\n        csv_file_upload_attributes(params[:file])\n      elsif params[:raw_file_content].present?\n        csv_raw_content_attributes(params[:raw_file_content].to_s)\n      end\n    end\n\n    def csv_file_upload_attributes(file)\n      raise_response csv_file_too_large_response if file.size > Import.max_csv_size\n      raise_response invalid_csv_file_type_response unless Import::ALLOWED_CSV_MIME_TYPES.include?(file.content_type)\n\n      [\n        file.read,","sourceCodeStart":157,"sourceCodeEnd":193,"githubUrl":"https://github.com/we-promise/sure/blob/e69894adb92547273377398c15f45c979cd9416a/app/models/import/preflight.rb#L157-L193","documentation":"Raised by Import::Preflight#preflight_account (app/models/import/preflight.rb:175) and rendered as HTTP 404 {error: 'record_not_found'} by Api::V1::BaseController#handle_not_found. It fires when the account_id sent to an import preflight request is not a UUID at all, or when it is a UUID that does not belong to an account in the authenticated family, because family.accounts.find is family-scoped. The valid_uuid? guard runs first so Postgres never receives a malformed uuid and throws its own 'invalid input syntax for type uuid' error.","triggerScenarios":"Calling the imports preflight endpoint with params[:account_id] blank; a slug or account number like 'ACC-1042'; a bracketed/URL-encoded UUID such as %7B...%7D; or a valid UUID of an account owned by a different family or already deleted.","commonSituations":"Copy-pasting an account number from the web UI instead of the UUID from GET /api/v1/accounts; using an API key issued for a different family or self-hosted instance; a stale account_id cached client-side after the account was deleted; HTTP clients that URL-encode braces around UUIDs.","solutions":["Fetch GET /api/v1/accounts with the same API key and use the id field of an account in that family","Omit account_id entirely when the preflight does not need account scoping","Strip whitespace/brackets and validate UUID format client-side before sending","If the account was deleted, recreate it or pick another account before importing"],"exampleFix":"# before\ncurl -H 'X-Api-Key: k' 'https://app/api/v1/imports/preflight?account_id=ACC-1042'\n# → 404 record_not_found\n\n# after\nID=$(curl -s -H 'X-Api-Key: k' https://app/api/v1/accounts | jq -r '.data[0].id')\ncurl -H 'X-Api-Key: k' \"https://app/api/v1/imports/preflight?account_id=$ID\"","handlingStrategy":"validation","validationCode":"UUID_RE = /[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}/i\naccount_id = account_id.to_s.strip.gsub(/[{}]/, '')\nraise ArgumentError, 'account_id must be a UUID' unless account_id.match?(UUID_RE)\nids = api.get('/api/v1/accounts').body['data'].map { |a| a['id'] }\nraise ArgumentError, 'account_id not in this family' unless ids.include?(account_id)","typeGuard":"def valid_uuid?(value)\n  value.is_a?(String) && value.match?(/[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}/i)\nend","tryCatchPattern":null,"preventionTips":["Always source account_id from GET /api/v1/accounts under the same API key","Never send UI slugs or human account numbers as account_id","Omit account_id when the preflight does not need account scoping"],"tags":["rails","api","import","preflight","uuid","http-404"],"backgroundTag":"record-not-found","analyzedSha":"e69894adb92547273377398c15f45c979cd9416a","analyzedAt":"2026-08-21T18:22:41.165Z","schemaVersion":2},"datasetVersion":"2026-08-21T23:17:16.201Z"}