{"record":{"id":"95aae52f9046b6b1","repo":"we-promise/sure","slug":"max-row-count-exceeded-95aae5","errorCode":"max_row_count_exceeded","errorMessage":"Import session has too many rows to publish.","messagePattern":"Import session has too many rows to publish\\.","errorType":"http","errorClass":"Import::MaxRowCountExceededError","httpStatus":422,"severity":"error","filePath":"app/models/import_session.rb","lineNumber":407,"sourceCode":"      result = import.import!(import_session: self)\n      import.update!(status: :complete, summary: result.fetch(:summary, {}), error_details: {})\n    rescue => error\n      import.update!(\n        status: :failed,\n        error: public_error_message_for(error),\n        error_details: error_details_for(error),\n        summary: failed_summary_for(error)\n      )\n      raise\n    end\n\n    def row_count_exceeded?\n      imports.sum(:rows_count) > SureImport.max_row_count\n    end\n\n    def validate_publishable_chunks!\n      raise ConflictError, \"import session has no chunks\" unless imports.exists?\n      raise Import::MaxRowCountExceededError if row_count_exceeded?\n      validate_expected_chunk_sequences!\n    end\n\n    def sync_chunk_row_counts!\n      raise ConflictError, \"import session has no chunks\" unless imports.exists?\n      imports.reload.each(&:sync_ndjson_rows_count!)\n    rescue ActiveStorage::FileNotFoundError\n      raise ConflictError, \"import session chunks are incomplete\"\n    end\n\n    def validate_expected_chunk_sequences!\n      return if expected_chunks.blank?\n\n      expected_sequences = (1..expected_chunks).to_a\n      actual_sequences = imports.pluck(:sequence).sort\n      return if actual_sequences == expected_sequences\n\n      missing_sequences = expected_sequences - actual_sequences","sourceCodeStart":389,"sourceCodeEnd":425,"githubUrl":"https://github.com/we-promise/sure/blob/e69894adb92547273377398c15f45c979cd9416a/app/models/import_session.rb#L389-L425","documentation":"ImportSession#validate_publishable_chunks! raises Import::MaxRowCountExceededError when the summed rows_count of all session chunks exceeds SureImport.max_row_count (ENV SURE_IMPORT_MAX_ROWS, default DEFAULT_MAX_ROW_COUNT). The cap protects the publish job from unbounded work. The API controller rescues it and renders code max_row_count_exceeded with message 'Import session has too many rows to publish.' (HTTP 422).","triggerScenarios":"Publishing a session whose chunks together contain more rows than the configured cap; note rows_count is only synced from the NDJSON files, so stale zero counts can also flip this after a re-sync.","commonSituations":"Bulk export larger than the deployment's limit; SURE_IMPORT_MAX_ROWS lowered after big sessions were created; multiple chunks each under the limit but summing over it.","solutions":["Split the data across multiple import sessions, each under SureImport.max_row_count rows.","Raise the limit via SURE_IMPORT_MAX_ROWS if the deployment can handle the payload, then retry publish.","Run sync_chunk_row_counts! (or a preflight/dry-run) first so rows_count is accurate before the check fires.","Strip unneeded record types from the NDJSON to reduce row count."],"exampleFix":"# before\nsession.publish!\n\n# after\nif session.imports.sum(:rows_count) > SureImport.max_row_count\n  head :unprocessable_entity # or split the upload\nelse\n  session.publish!\nend","handlingStrategy":"validation","validationCode":"session.imports.sum(:rows_count) <= SureImport.max_row_count","typeGuard":null,"tryCatchPattern":"begin\n  session.publish!\nrescue Import::MaxRowCountExceededError\n  head :unprocessable_entity # and split the upload\nend","preventionTips":["Run the preflight/dry-run warning (Import::Preflight already flags row counts over the limit) before publishing.","Show the effective limit (SURE_IMPORT_MAX_ROWS) in the upload UI.","Split large exports into multiple sessions up front."],"tags":["import","limit","validation","rails"],"backgroundTag":"row-limit-exceeded","analyzedSha":"e69894adb92547273377398c15f45c979cd9416a","analyzedAt":"2026-08-21T18:22:41.165Z","schemaVersion":2},"datasetVersion":"2026-08-21T23:17:16.201Z"}