mbleigh / acts-as-taggable-on

A tagging plugin for Rails applications that allows for custom tagging along dynamic contexts.
http://mbleigh.lighthouseapp.com/projects/10116-acts-as-taggable-on
MIT License
4.96k stars 1.2k forks source link

acts_as_ordered_taggable_on is not compatible with Rails 6.1 #1023

Open lapitsky opened 3 years ago

lapitsky commented 3 years ago

Issue

Starting with Rails 6.1, I cannot tag an entity that has an ordered list of tags using an owner object.

Details

When I try to tag an entity with a list of comma-separated taggings like below

owner.tag(entity, with: csv_list_for_taggable_gem, on: :positions)

I get the following error

     ActiveRecord::UnknownAttributeReference:
       Query method called with non-attribute argument(s): "public.taggings.id"

The entity uses acts_as_ordered_taggable_on :positions. This issue is caused by https://github.com/mbleigh/acts-as-taggable-on/blob/master/lib/acts_as_taggable_on/taggable/ownership.rb#L45. In Rails 6.1 in order to sort by an expression like public.taggings.id we need to wrap the expression in Arel.sql call. This way we will let Rails know that this is a safe expression in terms of SQL injection.

tannerhallman commented 3 years ago

What version of acts-as-taggable-on are you using?

lapitsky commented 3 years ago

@tannerhallman 7.0.0 Thank you for checking!

gsar commented 3 years ago

@lapitsky it works fine with rails 6.1.1 for me. are you by any chance setting table_name to include the public schema? the default behavior for table_name is to return the unadorned table name, as you can see below. rails has builtin support to recognize order('table.column') as safe, but doesn't recognize order('schema.table.column') as safe. might want to report this to the rails maintainers.

image

lapitsky commented 3 years ago

Oh, I see. I think this is because we use apartment gem that explicitly specifies public. prefix. Thank you for the response!

Merovex commented 3 years ago

Looks like this is resolved and needs to be closed.