Project

General

Profile

Bug #2193

Wrong parenthesis used at hosts.rb

Added by Dennis Hoppe over 6 years ago. Updated over 6 years ago.

Status:
Closed
Priority:
Normal
Assignee:
Category:
-
Target version:
Difficulty:
Triaged:
No
Bugzilla link:
Pull request:
Team Backlog:
Fixed in Releases:
Found in Releases:

Description

Hello,

i am using Foreman 1.1 with PostgreSQL 9.1 as database backend and the link "All Puppet Classes" is throwing the following SQL Error:

PG::Error: FEHLER: Spalte »Class« existiert nicht LINE 1: ...s" WHERE ("resources".host_id = 7) AND (restype = "Class" AN... ^ : SELECT title FROM "resources" WHERE ("resources".host_id = 7) AND (restype = "Class" AND title != "main" AND title != "Settings") ORDER BY title                                                                                                                                    

ActiveRecord::StatementInvalid
PG::Error: FEHLER: Spalte »Class« existiert nicht LINE 1: ...s" WHERE ("resources".host_id = 7) AND (restype = "Class" AN... ^ : SELECT title FROM "resources" WHERE ("resources".host_id = 7) AND (restype = "Class" AND title != "main" AND title != "Settings") ORDER BY title
app/models/host.rb:606:in `classes_from_storeconfigs'
app/views/hosts/storeconfig_klasses.html.erb:6:in `_app_views_hosts_storeconfig_klasses_html_erb___1446665967_70110018225800_0'
lib/foreman/thread_session.rb:31:in `clear_thread'

You should change the parenthesis at "/usr/share/foreman/app/models/hosts.rb" to make this work with PostgreSQL.

root@puppet:/usr/share/foreman/app/models# diff -Naur host.rb_2013-02-08 host.rb
--- host.rb_2013-02-08  2013-02-08 17:06:27.822667417 +0100
+++ host.rb     2013-02-08 17:09:03.725967925 +0100
@@ -603,7 +603,7 @@
   end

   def classes_from_storeconfigs
-    klasses = resources.all(:conditions => 'restype = "Class" AND title != "main" AND title != "Settings"', :select => :title, :order => :title)
+    klasses = resources.all(:conditions => "restype = 'Class' AND title != 'main' AND title != 'Settings'", :select => :title, :order => :title)
     klasses.map!(&:title).delete(:main)
     klasses
   end

Regards, Dennis

Associated revisions

Revision 5a301021 (diff)
Added by Dennis Hoppe over 6 years ago

fixes #2193 SQL error on Postgres 9.1 for classes_from_storeconfigs

Revision 83615388 (diff)
Added by Dennis Hoppe over 6 years ago

fixes #2193 SQL error on Postgres 9.1 for classes_from_storeconfigs

History

#1 Updated by Joseph Magen over 6 years ago

  • Status changed from New to Ready For Testing
  • Assignee set to Joseph Magen

Dennis,

Can you check if this fixes the SQL Error?

klasses = resources.select(:title).where(:restype => "Class").where("title <> ? AND title <> ?", "main", "Settings").order(:title)

I also issued a pull request with this fix - https://github.com/theforeman/foreman/pull/404

Thanks,

Joseph

#2 Updated by Dennis Hoppe over 6 years ago

Hello Joseph,

i tested your code and it fixed the SQL Error.

Regards, Dennis

#3 Updated by Ohad Levy over 6 years ago

  • Target version set to 1.2.0

#4 Updated by Dennis Hoppe over 6 years ago

  • Status changed from Ready For Testing to Closed
  • % Done changed from 0 to 100

Also available in: Atom PDF