we-promise/sure · error · Import::MaxRowCountExceededError

Import::MaxRowCountExceededError

Error message

Import::MaxRowCountExceededError

What it means

The same row-count guard re-checked inside the job-side publish path: it raises MaxRowCountExceededError when row_count_exceeded? holds at execution time — defense in depth if rows grew or enqueue bypassed publish_later. Unlike publish_later, this runs inside a rescue that writes status :failed with error 'Import::MaxRowCountExceededError' onto the import record.

Source

Thrown at app/models/import.rb:276

  def publish
    # A redelivered or stray ImportJob must not re-import data that already
    # committed (types without row dedup would double-apply), and must not
    # race a revert that owns the record. A failed import is deliberately NOT
    # blocked: its transaction rolled back, so a re-run is a safe retry.
    if complete? || reverting? || revert_failed?
      DebugLogEntry.capture(
        category: "background_jobs",
        level: "warn",
        message: "Import publish skipped: job redelivered while record was #{status}",
        source: self.class.name,
        family: family,
        metadata: { record_type: type, record_id: id, status: status }
      )
      return
    end

    raise MaxRowCountExceededError if row_count_exceeded?

    import!

    family.sync_later

    update! status: :complete
  rescue => error
    update! status: :failed, error: error.message
  end

  def revert_later
    raise "Import is not revertable" unless revertable?

    update! status: :reverting

    RevertImportJob.perform_later(self)
  end

View on GitHub (pinned to e69894adb9)

Solutions

  1. Inspect the import record: status is :failed with error 'Import::MaxRowCountExceededError'; row data is intact for re-splitting
  2. Reduce rows below max_row_count (delete excess rows or split into a new import) then publish again
  3. Always enqueue through publish_later so the guard fires before the job runs

Example fix

// before
ImportJob.perform_later(import) # bypasses the pre-enqueue guard

// after
import.publish_later # guarded: raises Import::MaxRowCountExceededError before enqueueing
Defensive patterns

Strategy: validation

Validate before calling

import.rows_count <= import.max_row_count && !%w[complete reverting revert_failed].include?(import.status) # re-check at job time; the guard raises and the rescue records status :failed

Prevention

When it happens

Trigger: ImportJob executing an import whose rows_count exceeds max_row_count at run time — rows appended after publish_later, a condition that appeared between upload and publish, or code enqueuing ImportJob directly without the publish_later guard.

Common situations: Rows added to the import record post-upload; job retries after data changed; custom code paths calling publish!/ImportJob directly.

Related errors


AI-assisted analysis of we-promise/sure@e69894adb9 (2026-08-21). Data as JSON: /api/errors/e158e3a8afd97718. Report an issue: GitHub.