Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Solidus appears to be referencing SpreeUser even though Spree.user_class is set to 'User' on an existing Rails app #3745

Open
paulsingh opened this issue Aug 27, 2020 · 6 comments
Labels
changelog:solidus_core Changes to the solidus_core gem type:bug Error, flaw or fault

Comments

@paulsingh
Copy link

Solidus Version:
2.10.2

To Reproduce

  1. After installing Solidus, run db:seed to get the default values installed and add a sample product to the store.
  2. Add the solidus_auth_devise gem and follow the instructions for setting Spree.user_class here: https://guides.solidus.io/developers/users/custom-authentication.html
  3. Drop the spree_users table from the DB since you'll be using your existing User class.
  4. Login with a test user, add the sample product to your cart and begin the checkout process. At the confirmation page, click 'Place Order' and you'll be presented with a SQLException: no such table: main.spree_users error.

Current behavior
The order should be completed successfully. Instead, an SQLException: no such table: main.spree_users error is thrown.

Expected behavior
The user should be able to successfully checkout / purchase their cart items.

Desktop (please complete the following information):

  • OS: MacOS Catalina 10.15.6
  • Chrome
  • Version 84.0.4147.105

Additional context
Log output is available here: https://gist.github.com/paulsingh/ab49d1977219971f72430351ffecc875

@paulsingh
Copy link
Author

I think I found the issue...

In db/schema.rb, I see the following: add_foreign_key "spree_wallet_payment_sources", "spree_users", column: "user_id"

Since I've set Spree.user_class to "User" in my app, I was able to create and run the following migration:

class ChangeForeignKeyOnWalletPaymentSources < ActiveRecord::Migration[6.0]
  def up
    remove_foreign_key "spree_wallet_payment_sources", "spree_users", column: "user_id"
    add_foreign_key "spree_wallet_payment_sources", "users", column: "user_id"
  end
  
  def down
    remove_foreign_key "spree_wallet_payment_sources", "users", column: "user_id"
    add_foreign_key "spree_wallet_payment_sources", "spree_users", column: "user_id"
  end
end

After restarting the app, my Order was able to successfully process!

So... the bad news: I'm still a complete noob to Solidus so not yet ready to put together a PR to fix this just yet. Just documenting this here in case it helps someone else in the meantime!

@kennyadsl
Copy link
Member

Thanks for reporting!

@kennyadsl kennyadsl added type:bug Error, flaw or fault changelog:solidus_core Changes to the solidus_core gem labels Aug 27, 2020
@peterberkenbosch
Copy link
Contributor

This might need some additional documentation around using your own user class. When setting up with your own user class it should work out of the box, however if you change it after the initial installer run it will fail like described here.

The migration here is using the configured table name correctly.
https://github.com/solidusio/solidus/blob/master/core/db/migrate/20160420044191_create_spree_wallet_payment_sources.rb#L10

@jarednorman
Copy link
Member

Good find, @peterberkenbosch!

@paulsingh Looks like you might just need to drop and recreate that foreign key.

@kennyadsl
Copy link
Member

@peterberkenbosch can you please help me understand how exactly you can set the custom user_class before running the solidus installer? In my understanding, it's the installer itself that creates the spree.rb initializer where we need to put the Spree.user_class = "MyStore::User" configuration, isn't it?

@peterberkenbosch
Copy link
Contributor

You are totally right @kennyadsl, we can't update this before installing. This needs a different approach indeed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
changelog:solidus_core Changes to the solidus_core gem type:bug Error, flaw or fault
Projects
None yet
Development

No branches or pull requests

4 participants