we-promise/sure · error · Import::MaxRowCountExceededError
max_row_count_exceeded
max_row_count_exceeded
Error message
Import session has too many rows to publish.
What it means
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).
Source
Thrown at app/models/import_session.rb:407
result = import.import!(import_session: self)
import.update!(status: :complete, summary: result.fetch(:summary, {}), error_details: {})
rescue => error
import.update!(
status: :failed,
error: public_error_message_for(error),
error_details: error_details_for(error),
summary: failed_summary_for(error)
)
raise
end
def row_count_exceeded?
imports.sum(:rows_count) > SureImport.max_row_count
end
def validate_publishable_chunks!
raise ConflictError, "import session has no chunks" unless imports.exists?
raise Import::MaxRowCountExceededError if row_count_exceeded?
validate_expected_chunk_sequences!
end
def sync_chunk_row_counts!
raise ConflictError, "import session has no chunks" unless imports.exists?
imports.reload.each(&:sync_ndjson_rows_count!)
rescue ActiveStorage::FileNotFoundError
raise ConflictError, "import session chunks are incomplete"
end
def validate_expected_chunk_sequences!
return if expected_chunks.blank?
expected_sequences = (1..expected_chunks).to_a
actual_sequences = imports.pluck(:sequence).sort
return if actual_sequences == expected_sequences
missing_sequences = expected_sequences - actual_sequencesView on GitHub (pinned to e69894adb9)
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.
Example fix
# before session.publish! # after if session.imports.sum(:rows_count) > SureImport.max_row_count head :unprocessable_entity # or split the upload else session.publish! end
Defensive patterns
Strategy: validation
Validate before calling
session.imports.sum(:rows_count) <= SureImport.max_row_count
Try / catch
begin session.publish! rescue Import::MaxRowCountExceededError head :unprocessable_entity # and split the upload end
Prevention
- 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.
When it happens
Trigger: 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.
Common situations: 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.
Related errors
- validation_failed
- validation_failed
- validation_failed
- #{key} must be an ISO 8601 date
- #{key} must be an ISO 8601 date
AI-assisted analysis of we-promise/sure@e69894adb9 (2026-08-21).
Data as JSON: /api/errors/95aae52f9046b6b1.
Report an issue: GitHub.