{"record":{"id":"27e240f731de7086","repo":"spree/spree","slug":"calling-spree-carts-associate-with-user-is-depr","errorCode":null,"errorMessage":"Calling Spree::Carts::Associate with user: is deprecated and will be removed in Spree 6.1. Pass customer: instead.","messagePattern":"Calling Spree::Carts::Associate with user: is deprecated and will be removed in Spree 6\\.1\\. Pass customer: instead\\.","errorType":"console","errorClass":null,"httpStatus":null,"severity":"warning","filePath":"spree/core/app/services/spree/carts/associate.rb","lineNumber":12,"sourceCode":"module Spree\n  module Carts\n    class Associate\n      prepend Spree::ServiceModule::Base\n\n      def call(guest_cart: nil, guest_order: nil, customer: nil, user: nil, override_email: true, guest_only: false)\n        if guest_order\n          Spree::Deprecation.warn('Calling Spree::Carts::Associate with guest_order: is deprecated and will be removed in Spree 6.1. Pass guest_cart: instead.')\n          guest_cart ||= guest_order\n        end\n        if user && customer.nil?\n          Spree::Deprecation.warn('Calling Spree::Carts::Associate with user: is deprecated and will be removed in Spree 6.1. Pass customer: instead.')\n          customer = user\n        end\n        return failure(guest_cart, 'Already assigned to a customer') if guest_only && guest_cart.customer.present? && guest_cart.customer != customer\n\n        guest_cart.customer       = customer\n        guest_cart.email          = customer.email if override_email\n        # Only valid saved defaults are copied — update_all below skips\n        # validations, so a broken address-book entry must not land on the\n        # cart. Digital-only checkouts never receive a ship address.\n        guest_cart.bill_address ||= customer.bill_address if customer.bill_address&.valid?\n        guest_cart.ship_address ||= customer.ship_address if customer.ship_address&.valid? && guest_cart.delivery_step_required?\n\n        changes = {\n          customer_id: guest_cart.customer&.id,\n          email: guest_cart.email,\n          bill_address_id: guest_cart.bill_address&.id,\n          ship_address_id: guest_cart.ship_address&.id\n        }.compact","sourceCodeStart":1,"sourceCodeEnd":30,"githubUrl":"https://github.com/spree/spree/blob/06bf66a8684b9de03210bbb2ddc8c1f5ba522fa2/spree/core/app/services/spree/carts/associate.rb#L1-L30","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","solutions":["Rename the keyword: Spree::Carts::Associate.call(guest_cart: cart, customer: customer).","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.","Grep for `user:` in calls to Carts::Associate and remove any both-keyword call sites that were accidentally silencing the warning.","Run the suite with deprecations raised to confirm the keyword is gone."],"exampleFix":"# before\nSpree::Carts::Associate.call(guest_cart: cart, user: user)\n\n# after\nSpree::Carts::Associate.call(guest_cart: cart, customer: customer)","handlingStrategy":"validation","validationCode":"# Never rely on the both-keywords trick that silences the warning\nraise ArgumentError, 'pass customer:, not user:' if defined?(customer).nil?\n\nkwargs =\n  if Spree::Carts::Associate.instance_method(:call).parameters.any? { |_, name| name == :customer }\n    { guest_cart: cart, customer: account }\n  else\n    { guest_order: cart, user: account }\n  end\nSpree::Carts::Associate.call(**kwargs)","typeGuard":"# @return [Boolean] true when the service accepts customer:\ndef spree_associate_customer_kwarg?\n  Spree::Carts::Associate.instance_method(:call).parameters.any? { |_, name| name == :customer }\nend","tryCatchPattern":null,"preventionTips":["Passing both user: and customer: hides the warning without fixing the call — forbid the pattern in review.","Migrate account resolution to customers (Spree.customer_class) alongside the keyword rename; Spree.user_class is deprecated with it.","Add a spec that calls Associate with only post-split keywords and runs with deprecations raised."],"tags":["deprecation","spree","cart","keyword-argument","customer-rename"],"backgroundTag":"deprecated-keyword-argument","analyzedSha":"06bf66a8684b9de03210bbb2ddc8c1f5ba522fa2","analyzedAt":"2026-08-21T14:59:48.125Z","schemaVersion":2},"datasetVersion":"2026-08-21T18:17:14.833Z"}