spree/spree · warning

Calling Spree::Carts::Associate with user: is deprecated and

Error message

Calling Spree::Carts::Associate with user: is deprecated and will be removed in Spree 6.1. Pass customer: instead.

What it means

Spree 6.0 renamed the storefront account concept from User to Customer (platform-auth rework), so Spree::Carts::Associate takes customer:. The source shows the bridge only fires when user: is given AND customer: is nil (customer = user), so passing both silences the warning — a trap that hides the migration. The user keyword is removed in 6.1.

Source

Thrown at spree/core/app/services/spree/carts/associate.rb:12

module Spree
  module Carts
    class Associate
      prepend Spree::ServiceModule::Base

      def call(guest_cart: nil, guest_order: nil, customer: nil, user: nil, override_email: true, guest_only: false)
        if guest_order
          Spree::Deprecation.warn('Calling Spree::Carts::Associate with guest_order: is deprecated and will be removed in Spree 6.1. Pass guest_cart: instead.')
          guest_cart ||= guest_order
        end
        if user && customer.nil?
          Spree::Deprecation.warn('Calling Spree::Carts::Associate with user: is deprecated and will be removed in Spree 6.1. Pass customer: instead.')
          customer = user
        end
        return failure(guest_cart, 'Already assigned to a customer') if guest_only && guest_cart.customer.present? && guest_cart.customer != customer

        guest_cart.customer       = customer
        guest_cart.email          = customer.email if override_email
        # Only valid saved defaults are copied — update_all below skips
        # validations, so a broken address-book entry must not land on the
        # cart. Digital-only checkouts never receive a ship address.
        guest_cart.bill_address ||= customer.bill_address if customer.bill_address&.valid?
        guest_cart.ship_address ||= customer.ship_address if customer.ship_address&.valid? && guest_cart.delivery_step_required?

        changes = {
          customer_id: guest_cart.customer&.id,
          email: guest_cart.email,
          bill_address_id: guest_cart.bill_address&.id,
          ship_address_id: guest_cart.ship_address&.id
        }.compact

View on GitHub (pinned to 06bf66a868)

Solutions

  1. Rename the keyword: Spree::Carts::Associate.call(guest_cart: cart, customer: customer).
  2. If the caller still produces a legacy user, resolve the corresponding customer first — 6.0 storefront accounts are customers, and Spree.user_class itself is a deprecated shell.
  3. Grep for `user:` in calls to Carts::Associate and remove any both-keyword call sites that were accidentally silencing the warning.
  4. Run the suite with deprecations raised to confirm the keyword is gone.

Example fix

# before
Spree::Carts::Associate.call(guest_cart: cart, user: user)

# after
Spree::Carts::Associate.call(guest_cart: cart, customer: customer)
Defensive patterns

Strategy: validation

Validate before calling

# Never rely on the both-keywords trick that silences the warning
raise ArgumentError, 'pass customer:, not user:' if defined?(customer).nil?

kwargs =
  if Spree::Carts::Associate.instance_method(:call).parameters.any? { |_, name| name == :customer }
    { guest_cart: cart, customer: account }
  else
    { guest_order: cart, user: account }
  end
Spree::Carts::Associate.call(**kwargs)

Type guard

# @return [Boolean] true when the service accepts customer:
def spree_associate_customer_kwarg?
  Spree::Carts::Associate.instance_method(:call).parameters.any? { |_, name| name == :customer }
end

Prevention

When it happens

Trigger: Spree::Carts::Associate.call(guest_cart: cart, user: user) — checkout/login flows, extensions and specs that still resolve the account via Spree.user_class and hand it to the cart association service.

Common situations: Apps upgraded to 6.0 where authentication still yields a legacy user object; extensions calling Associate with user:; specs asserting guest-cart adoption written before the rename.

Related errors


AI-assisted analysis of spree/spree@06bf66a868 (2026-08-21). Data as JSON: /api/errors/27e240f731de7086. Report an issue: GitHub.