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

tagged_with adding backslash to tag names when any: true #1116

Open
russellbrown opened this issue Oct 30, 2023 · 0 comments
Open

tagged_with adding backslash to tag names when any: true #1116

russellbrown opened this issue Oct 30, 2023 · 0 comments

Comments

@russellbrown
Copy link

russellbrown commented Oct 30, 2023

When I use tagged_with with multiple tags and any: true I always get 0 results and it seems to be due to a backslash getting added to all but the last tag in the SQL query.

Suppose I have tagged a post (id=1) with 'ABC'.

# The post is found as expected
Post.tagged_with(["ABC"], any: true).find(1)
=> #<Article id: 1...

But:

Post.tagged_with(["ABC","DEF","XYZ"], any: true).find(1)
=> ActiveRecord::RecordNotFound

In the last example the SQL query generated is adding backslashes to all but the final tag name:

SELECT  "posts".* FROM "posts" WHERE EXISTS (SELECT * FROM "taggings" WHERE "taggings"."taggable_id" = "posts"."id" AND "taggings"."taggable_type" = 'Post' AND "taggings"."tag_id" IN (SELECT "tags"."id" FROM "tags" WHERE (LOWER("tags"."name") ILIKE 'abc\' ESCAPE '!' OR LOWER("tags"."name") ILIKE 'def\' ESCAPE '!' OR LOWER("tags"."name") ILIKE 'xyz' ESCAPE '!'))) AND "posts"."id" = 1 LIMIT 1;

When I copy and paste that query into the database (psql) console and run it it returns 0 rows. But when I manually remove the backslashes from the first 2 tag names and re-run the query I get the row I was originally expecting.

Is this a bug?

My setup:

ruby 2.4.0
rails 5.2.8
acts-as-taggable-on 8.1.0

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant