Actions
Bug #32641
closedPG::AmbiguousColumn when listing domains
Description
Hi,
When a user who is not admin or does not have any role allowing to see all hosts, browsing /domains leads to a PG::AmbiguousColumn exception as follows:
Oops, we're sorry but something went wrong PG::AmbiguousColumn: ERROR: column reference "domain_id" is ambiguous LINE 1: SELECT COUNT(DISTINCT "hosts"."id") AS count_id, domain_id A... ^
Digging a bit deeper, I managed to reproduce it using the Rails console by playing a bit with what counted_hosts does when the template calls hosts_count[domain]
> User.current = User.find_by_login('myuser') > hosts_scope = Host::Managed.reorder('') > hosts_scope = hosts_scope.joins(:primary_interface) irb(main):004:0> hosts_scope.authorized(:view_hosts).group("domain_id").count Traceback (most recent call last): 2: from lib/tasks/console.rake:5:in `block in <top (required)>' 1: from (irb):4 ActiveRecord::StatementInvalid (PG::AmbiguousColumn: ERROR: column reference "domain_id" is ambiguous) LINE 1: SELECT COUNT(DISTINCT "hosts"."id") AS count_id, domain_id A...
However if I manually specify that I want to group by nics's domain_id it works as expected:
> hosts_scope.authorized(:view_hosts).group("nics.domain_id").count => {1=>510}
As I mentioned before, admin users or users with a role with a filter "view_hosts" unlimited do not experience this problem.
Actions