spree-contrib / spree_globalize

Adds support for model translations (multi-language stores) using Globalize gem
https://spreecommerce.org
BSD 3-Clause "New" or "Revised" License
24 stars 101 forks source link

ActiveRecord::StatementInvalid in Spree::Admin::Products#index after installation #52

Open exocode opened 5 years ago

exocode commented 5 years ago

Hi there, I try to get an fresh installed Spree Shop running with "spree_globalize".

• When I am logged in as admin • and I click on products • Then I see this error:

ActiveRecord::StatementInvalid in Spree::Admin::Products#index

Showing /Users/janjezek/.rbenv/versions/2.5.1/lib/ruby/gems/2.5.0/gems/spree_backend-3.6.4/app/views/spree/admin/products/index.html.erb where line #68 raised:

Mysql2::Error: Expression #1 of ORDER BY clause is not in SELECT list, references column 'demo520-spree_development.spree_products.name' which is not in SELECT list; this is incompatible with DISTINCT: SELECT  DISTINCT `spree_products`.`id`, `spree_products`.`available_on`, `spree_products`.`discontinue_on`, `spree_products`.`deleted_at`, `spree_products`.`tax_category_id`, `spree_products`.`shipping_category_id`, `spree_products`.`created_at`, `spree_products`.`updated_at`, `spree_products`.`promotionable` FROM `spree_products` WHERE `spree_products`.`deleted_at` IS NULL AND (`spree_products`.discontinue_on IS NULL or `spree_products`.discontinue_on >= '2018-10-14 19:08:22.259918') ORDER BY `spree_products`.`name` ASC LIMIT 25 OFFSET 0

129  | def query(sql, options = {})       
130     Thread.handle_interrupt(::Mysql2::Util::TIMEOUT_ERROR_CLASS => :never) do
131        _query(sql, @query_options.merge(options))
132     end
133  end

Full Stacktrace here: http://pasted.co/2c4be2fa

What I've done

ruby '2.5.1'
gem 'rails', '~> 5.2.0'

gem 'spree', '~> 3.6.4'
gem 'spree_auth_devise', '~> 3.3'
gem 'spree_gateway', '~> 3.3'

gem 'spree_i18n', github: 'spree-contrib/spree_i18n'
gem 'globalize', git: 'https://github.com/globalize/globalize'
gem 'activemodel-serializers-xml'
gem 'spree_globalize', github: 'spree-contrib/spree_globalize'

I uploaded a git Repo to jumpstart: https://github.com/exocode/demo520-spree364

git clone git@github.com:exocode/demo520-spree364.gitcd demo520-spree364bundle installnano database.yml to your needs • rake db:snapshot:restore to restore same state where it fails

I hope someone can help me.

khataev commented 5 years ago

I had the same issue. What's interesting - problem appears only on postgres database with i18n/globalize gems. When I create local demo on default sqlite3 - everything is ok.

AhmedAliIbrahim commented 5 years ago

Did you find any solution or workaround ?

khataev commented 5 years ago

No, I did not

mrbrdo commented 2 years ago

It has to do with Postgres, which is stricter on proper SQL, I have the same issue(s). Looking for a solution as well, because it comes up through multiple paths (different methods of friendly_id and the globalize version of it). It seems the main culprit is the *-globalize gems. I also get ActiveRecord::StatementInvalid: PG::GroupingError: ERROR: column "spree_product_translations.id" must appear in the GROUP BY clause or be used in an aggregate function for a different query.