Skip to content

Support Rails 8: build_batch_orders now takes a cursor argument - #1

Open
mykhi wants to merge 1 commit into
masterfrom
rails-8-support
Open

mykhi wants to merge 1 commit into
masterfrom
rails-8-support

Conversation

@mykhi

@mykhi mykhi commented Sep 7, 2026

Copy link
Copy Markdown

Rails 8 changed the private ActiveRecord::Batches#build_batch_orders signature from (order) to (cursor, order) to support composite primary keys:

# Rails 8.0
def build_batch_orders(cursor, order)
  cursor.zip(Array(order)).map do |column, order_|
    [column, order_ || DEFAULT_ORDER]
  end
end

The IS_RAILS_7_1_PLUS branch still called the one-arg form, so every pluck_in_batches / pluck_each call on an ActiveRecord relation raised:

ArgumentError: wrong number of arguments (given 1, expected 2)

This adds an IS_RAILS_8_PLUS branch that passes Array(primary_key) as the cursor. Behaviour is unchanged — both forms produce { primary_key => :asc }. Rails < 8 paths are untouched.

Verified against maxio-com/chargify on the Rails 8 upgrade branch (fnd-840-rails-8-upgrade, PR #30000), which was failing 22 examples on this error:

  • spec/jobs/batch/backfill_customer_maxioid_spec.rb — 25 examples, 0 failures
  • spec/lib/jobs/batch/proforma_invoice_pdf_zip_export_spec.rb — 17 examples, 0 failures

Also exercised the call shapes used across that codebase (single primary key, multi-column, non-primary-key column, string column names, pluck_each, and a relation with a pre-existing order) — results and ascending ordering match Rails 7.2.

@mykhi mykhi self-assigned this Sep 7, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant