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

Could not open tag link (PG::AmbiguousColumn: ERROR: column reference "id" is ambiguous) #392

Open
iwasi-1234 opened this issue Dec 23, 2020 · 2 comments

Comments

@iwasi-1234
Copy link

iwasi-1234 commented Dec 23, 2020

Environment

Environment:
  Redmine version                4.1.1.stable
  Ruby version                   2.6.2-p47 (2019-03-13) [x86_64-linux]
  Rails version                  5.2.4.2
  Environment                    production
  Database adapter               PostgreSQL
  Mailer queue                   ActiveJob::QueueAdapters::AsyncAdapter
  Mailer delivery                smtp
SCM:
  Subversion                     1.7.14
  Git                            1.8.3.1
  Filesystem                     
Redmine plugins:
  redmine_custom_auto_complete   0.0.1
  redmine_export_with_journals   0.1.0
  redmine_issue_templates        1.1.0
  redmine_issues_panel           0.0.1
  redmine_issues_summary_graph   0.0.10
  redmine_knowledgebase          4.1.1
  redmine_persist_wfmt           2.0.1
  redmine_smile_togglesidebar    1.0.7
  redmine_theme_changer          0.4.0
  redmine_watcher_filter         4.0.0-alpha
  redmine_wiki_extensions        0.9.2
  selectbox_autocompleter        1.2.1
  view_customize                 2.8.0

Description

I migrated from redmine 3.4.13 to redmine 4.1.
I could create KB article and show the article on "overview"/"content". But I couldn't refer to tag link, and displayed "Internal error" message:
knowlegdebase_overview

Internal error

An error occurred on the page you were trying to access.
If you continue to experience problems please contact your Redmine administrator for assistance.

If you are the Redmine administrator, check your log files for details about the error.

Back

And following message were confirmed in production.log:

  KbArticle Load (1.5ms)  SELECT DISTINCT kb_articles.*  FROM "kb_articles" INNER JOIN taggings kb_articles_taggings ON kb_articles_taggings.taggable_id = kb_articles.id AND kb_articles_taggings.taggable_type = 'KbArticle' INNER JOIN tags kb_articles_tags ON kb_articles_tags.id = kb_articles_taggings.tag_id WHERE "kb_articles"."project_id" = $1 AND ((kb_articles_tags.name LIKE 'tagtest')) ORDER BY title asc  [["project_id", 33]]
  RedmineCrm::ActsAsTaggable::Tag Load (0.5ms)  SELECT tags.id, tags.name, COUNT(*) AS count FROM "tags" INNER JOIN taggings ON tags.id = taggings.tag_id INNER JOIN kb_articles ON kb_articles.id = taggings.taggable_id WHERE ("id" = 181 AND taggings.taggable_type = 'KbArticle') GROUP BY tags.id, tags.name HAVING (COUNT(*) > 0)
Completed 500 Internal Server Error in 29ms (ActiveRecord: 12.4ms)
  
ActiveRecord::StatementInvalid (PG::AmbiguousColumn: ERROR:  column reference "id" is ambiguous
LINE 1: ...s ON kb_articles.id = taggings.taggable_id WHERE ("id" = 181...
                                                             ^
: SELECT tags.id, tags.name, COUNT(*) AS count FROM "tags" INNER JOIN taggings ON tags.id = taggings.tag_id INNER JOIN kb_articles ON kb_articles.id = taggings.taggable_id WHERE ("id" = 181 AND taggings.taggable_type = 'KbArticle') GROUP BY tags.id, tags.name HAVING (COUNT(*) > 0)):
  
plugins/redmine_knowledgebase/app/controllers/categories_controller.rb:133:in `sort'
plugins/redmine_knowledgebase/app/controllers/categories_controller.rb:133:in `prepare'
plugins/redmine_knowledgebase/app/controllers/categories_controller.rb:20:in `index'
lib/redmine/sudo_mode.rb:65:in `sudo_mode'

tagtest is sample tag.

Is any workaround of this issue?

Regards,

@iwasi-1234 iwasi-1234 changed the title PG::AmbiguousColumn: ERROR: column reference "id" is ambiguous Could not open tag link (PG::AmbiguousColumn: ERROR: column reference "id" is ambiguous) Dec 31, 2020
@kay54068
Copy link

kay54068 commented Oct 1, 2021

I have the same issue

@iwasi-1234
Copy link
Author

I confirmed that this issue occurs in PostgreSQL and doesn't in MySQL.

My workaround is as follows:

--- app/controllers/categories_controller.rb.bak        2021-10-21 23:10:28.015888777 +0900
+++ app/controllers/categories_controller.rb    2021-10-22 01:56:43.067936471 +0900
@@ -127,7 +127,7 @@
       @tag = params[:tag]
       @tag_array = *@tag.split(',')
       @tag_hash = Hash[ @tag_array.map{ |tag| [tag.downcase, 1] } ]
-      @articles = KbArticle.where(id: @articles.tagged_with(@tag).map(&:id))
+      @articles = KbArticle.where('kb_articles.id in (?)', @articles.tagged_with(@tag).map(&:id))
     end
 
     @tags = @articles.tag_counts.sort { |a, b| a.name.downcase <=> b.name.downcase }

I don't test on MySQL.

Regards,

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

2 participants