antiwork/gumroad · error · ActiveRecord::RecordInvalid

This commission has already been completed, so its files can

Error message

This commission has already been completed, so its files can no longer be changed.

What it means

Raised as ActiveRecord::RecordInvalid by CommissionsController#update's ensure_files_can_be_changed! guard when the target commission's files are no longer editable. Editability is defined by Commission#files_are_editable? (app/models/commission.rb:113) as !is_completed? && completion_purchase.nil?, so the lock applies both after completion and while a completion charge is still settling. The controller renders the model's :base error to the seller; it is a state guard, not a transport failure.

Source

Thrown at app/controllers/commissions_controller.rb:43

    begin
      commission.create_completion_purchase!
    rescue ActiveRecord::RecordInvalid => e
      errors = e.record&.errors&.full_messages.presence || ["Failed to complete commission"]
      return render json: { errors: }, status: :unprocessable_entity
    rescue => e
      Rails.logger.error("Commission #{params[:id]} completion failed: #{e.class}: #{e.message}")
      return render json: { errors: ["Failed to complete commission"] }, status: :unprocessable_entity
    end

    head :no_content
  end

  private
    def ensure_files_can_be_changed!(commission)
      return if commission.files_are_editable?

      commission.errors.add(:base, "This commission has already been completed, so its files can no longer be changed.")
      raise ActiveRecord::RecordInvalid, commission
    end

    def permitted_params
      params.permit(file_signed_ids: [])
    end
end

View on GitHub (pinned to afeacbd394)

Solutions

  1. Gate the edit affordance on the commission's files_are_editable? value (already serialized to the seller UI) instead of status alone, so file controls disappear the moment a completion purchase exists.
  2. If the completion charge is merely settling (commission still in_progress but completion_purchase present), disable file edits with a 'completion in progress' note and re-check after the charge settles.
  3. If the commission is genuinely completed, stop attempting file mutations — the state is terminal by design; deliverables were justified by the charge.
  4. In API clients, rescue ActiveRecord::RecordInvalid from this endpoint and surface commission.errors.full_messages to the user.

Example fix

# before (controller-side callers / client code)
commission.update!(permitted_params) # raises RecordInvalid after completion

# after
def update_files(commission, file_signed_ids)
  return { locked: true, message: "Files can no longer be changed." } unless commission.files_are_editable?

  commission.update!(file_signed_ids:)
end
Defensive patterns

Strategy: validation

Validate before calling

# Before PUT/PATCH of commission files
return render_locked(commission) unless commission.files_are_editable?

Try / catch

begin
  commission.update!(permitted_params)
rescue ActiveRecord::RecordInvalid
  render json: { errors: commission.errors.full_messages }, status: :unprocessable_entity
end

Prevention

When it happens

Trigger: PUT/PATCH to the commissions update endpoint (the before_action at app/controllers/commissions_controller.rb:7 fires for every file change) after (a) the commission was completed, or (b) a completion purchase exists even though status is still in_progress (completion charge settling in the buyer's currency). Any file_signed_ids update in those states raises immediately.

Common situations: Seller keeps a stale commission edit page open, completes the commission in another tab, then saves file changes from the stale tab. Or the UI allows re-uploading files while a completion charge is in flight; the serialized files_are_editable? flag exists precisely so the UI affordances match what the controller accepts.

Related errors


AI-assisted analysis of antiwork/gumroad@afeacbd394 (2026-08-21). Data as JSON: /api/errors/f0e6bb1924d4da93. Report an issue: GitHub.