{"record":{"id":"75bcd24c86e86ba2","repo":"we-promise/sure","slug":"validation-failed-75bcd2","errorCode":"validation_failed","errorMessage":"account_id must be a valid UUID","messagePattern":"account_id must be a valid UUID","errorType":"validation","errorClass":"Api::V1::ValuationsController::InvalidFilterError","httpStatus":422,"severity":"warning","filePath":"app/controllers/api/v1/valuations_controller.rb","lineNumber":257,"sourceCode":"      @valuation = @entry.entryable\n    rescue ActiveRecord::RecordNotFound\n      render json: {\n        error: \"not_found\",\n        message: \"Valuation not found\"\n      }, status: :not_found\n    end\n\n    def ensure_read_scope\n      authorize_scope!(:read)\n    end\n\n    def ensure_write_scope\n      authorize_scope!(:write)\n    end\n\n    def apply_filters(query)\n      if params[:account_id].present?\n        raise InvalidFilterError, \"account_id must be a valid UUID\" unless valid_uuid?(params[:account_id])\n\n        query = query.where(account_id: params[:account_id])\n      end\n      query = query.where(\"entries.date >= ?\", parse_date_param(:start_date)) if params[:start_date].present?\n      query = query.where(\"entries.date <= ?\", parse_date_param(:end_date)) if params[:end_date].present?\n      query\n    end\n\n    def parse_date_param(key)\n      Date.iso8601(params[key].to_s)\n    rescue ArgumentError\n      raise InvalidFilterError, \"#{key} must be an ISO 8601 date\"\n    end\n\n    def safe_page_param\n      page = params[:page].to_i\n      page > 0 ? page : 1\n    end","sourceCodeStart":239,"sourceCodeEnd":275,"githubUrl":"https://github.com/we-promise/sure/blob/e69894adb92547273377398c15f45c979cd9416a/app/controllers/api/v1/valuations_controller.rb#L239-L275","documentation":"Api::V1::ValuationsController#apply_filters (app/controllers/api/v1/valuations_controller.rb:256-259) validates the account_id query param with valid_uuid? before filtering. A present but malformed account_id raises InvalidFilterError 'account_id must be a valid UUID', rescued into a 422 validation_failed response. Format only — existence is not checked.","triggerScenarios":"GET /api/v1/valuations?account_id=main or ?account_id=123. A well-formed UUID for a nonexistent account returns an empty list, not an error.","commonSituations":"Passing the account name or legacy numeric id instead of the UUID; copying ids between query and JSON body contexts and losing characters; templates that leave a placeholder like 'ACCOUNT_ID'.","solutions":["Send account_id as a canonical UUID from GET /api/v1/accounts","Validate UUID format client-side before the request","Remember valid-but-unknown account ids yield empty data, not errors — verify against the accounts list if results look wrong","URL-encode the param; avoid curly quotes from rich-text copy/paste"],"exampleFix":"# before\nGET /api/v1/valuations?account_id=checking\n# after\nGET /api/v1/valuations?account_id=0e8d1ceb-5b6d-4a85-9f2e-74f3b1a2c9d4","handlingStrategy":"validation","validationCode":"UUID_RE = /\\A[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}\\z/i\nraise ArgumentError, 'account_id must be a valid UUID' if account_id && !UUID_RE.match?(account_id)","typeGuard":"def valid_uuid?(v) = v.to_s.match?(/\\A[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}\\z/i)","tryCatchPattern":"begin\n  client.get('/api/v1/valuations', { account_id: aid })\nrescue Faraday::UnprocessableEntity => e\n  # 422 validation_failed 'account_id must be a valid UUID'\nend","preventionTips":["Take account_id from GET /api/v1/accounts","Reject placeholder values like 'ACCOUNT_ID' in request builders","Valid-but-unknown ids return empty data — cross-check the accounts list"],"tags":["rails","query-params","validation","http-422","uuid"],"backgroundTag":"invalid-query-parameter","analyzedSha":"e69894adb92547273377398c15f45c979cd9416a","analyzedAt":"2026-08-21T18:22:41.165Z","schemaVersion":2},"datasetVersion":"2026-08-21T23:17:16.201Z"}