Setting up a new store, working on easypost, but a...
# support
g
Setting up a new store, working on easypost, but a fresh install and config (I ran the install command with migrations and set the config pieces) throws
Copy code
PG::UniqueViolation: ERROR: duplicate key value violates unique constraint "spree_shipping_rates_join_index"
DETAIL: Key (shipment_id, shipping_method_id)=(9, 2) already exists.
when I click "save and continue" after entering the shipping address. Looking at the logs and I see
Copy code
[1m[36mSpree::ShippingRate Create (0.7ms)[0m  [1m[32mINSERT INTO "spree_shipping_rates" ("shipment_id", "shipping_method_id", "selected", "cost", "created_at", "updated_at", "tax_rate_id", "name", "easy_post_shipment_id", "easy_post_rate_id") VALUES ($1, $2, $3, $4, $5, $6, $7, $8, $9, $10) RETURNING "id"[0m  [["shipment_id", 9], ["shipping_method_id", 2], ["selected", true], ["cost", "23.75"], ["created_at", "2022-12-07 15:25:17.919924"], ["updated_at", "2022-12-07 15:25:17.919924"], ["tax_rate_id", nil], ["name", "USPS Express"], ["easy_post_shipment_id", "shp_683cdccae3f34e65b8e77f997c6d84e1"], ["easy_post_rate_id", "rate_2d90fba67a874e62ae4dd45ac51ce490"]]
  ↳ app/controllers/checkouts_controller.rb:53:in `transition_forward'
  [1m[36mSpree::ShippingRate Create (1.4ms)[0m  [1m[32mINSERT INTO "spree_shipping_rates" ("shipment_id", "shipping_method_id", "selected", "cost", "created_at", "updated_at", "tax_rate_id", "name", "easy_post_shipment_id", "easy_post_rate_id") VALUES ($1, $2, $3, $4, $5, $6, $7, $8, $9, $10) RETURNING "id"[0m  [["shipment_id", 9], ["shipping_method_id", 2], ["selected", false], ["cost", "23.75"], ["created_at", "2022-12-07 15:25:17.924424"], ["updated_at", "2022-12-07 15:25:17.924424"], ["tax_rate_id", nil], ["name", "USPS Express"], ["easy_post_shipment_id", "shp_683cdccae3f34e65b8e77f997c6d84e1"], ["easy_post_rate_id", "rate_127e8d2ca0504d1ea584d5b911678396"]]
  ↳ app/controllers/checkouts_controller.rb:53:in `transition_forward'
It appears to be trying to insert twice. I haven't done any shipping customizations, the store is still mostly vanilla. I'm running on solidus 3 (
gem "solidus_core", "~> 3.2"
). I can dig into the gem's code to try to figure it out, but was wondering if anybody had any ideas that would save me needing to dig around.
m
I think the easypost extension does a thing that might not play well with that uniqueness constraint: Rather than generating a new shipping method for each shipping method supported by easypost, it lumps them all under one Solidus shipping method. This breaks the assumption at the database level that there can't be more than one shipping rate with the same shipping method for any shipment.
Easy way out: remove the uniqueness constraint.
Hard way out: Refactor the gem so that it creates a new shipping method for each shipping method you want to offer in your store.
g
Gotcha, that makes sense. I'll experiment with removing the constraint first, and see how that goes. Refactoring the gem is exactly what I'm hoping to avoid 😛
I got it sorted and wanted to give you an update so you'd know what was going on. Turns out it was my fault, but I didn't know it at the time. Part of the easypost onboarding process was to add a new carrier, so I added USPS, since that's what I was going to test with. What I didn't realize was that I had inadvertently created a scenario where it was returning 2 sets of USPS results, which was running into the duplicate key constraint. Once I removed the extra carrier, everything worked as expected.