Bug 1921150

Summary: Tasks view fails for non-admin with PG::SyntaxError: ERROR: syntax error at or near "'1,6,4,3,5'"
Product: Red Hat Satellite Reporter: Peter Ondrejka <pondrejk>
Component: Tasks PluginAssignee: Adam Ruzicka <aruzicka>
Status: CLOSED ERRATA QA Contact: Peter Ondrejka <pondrejk>
Severity: high Docs Contact:
Priority: unspecified    
Version: 6.9.0CC: aruzicka, pcreech, zhunting
Target Milestone: 6.9.0Keywords: Triaged
Target Release: Unused   
Hardware: Unspecified   
OS: Unspecified   
Whiteboard:
Fixed In Version: tfm-rubygem-foreman-tasks-3.0.5 Doc Type: If docs needed, set a value
Doc Text:
Story Points: ---
Clone Of: Environment:
Last Closed: 2021-04-21 13:10:30 UTC Type: Bug
Regression: --- Mount Type: ---
Documentation: --- CRM:
Verified Versions: Category: ---
oVirt Team: --- RHEL 7.3 requirements from Atomic Host:
Cloudforms Team: --- Target Upstream Version:
Embargoed:
Bug Depends On:    
Bug Blocks: 1741943    
Attachments:
Description Flags
prodlog
none
prodlog2 none

Description Peter Ondrejka 2021-01-27 15:30:52 UTC
Description of problem:
Viewing the tasks page as non admin user with cloned manager role that has organizations assigned fails in ui with:

Could not receive data: Request failed with status code 500

prodlog (attached) shows:

[I|app|f5671e24] Backtrace for 'Action failed' error (ActionView::Template::      Error): PG::SyntaxError: ERROR:  syntax error at or near "'1,6,4,3,5'"
   f5671e24 | LINE 9: ...foreman_tasks_locks_taxonomy5f5e24.resource_id IN '1,6,4,3,5...
   f5671e24 |                                                              ^

Version-Release number of selected component (if applicable):

Satellite 6.8 snap 10

How reproducible:
always

Steps to Reproduce:
1. Have a satellite with mutliple orgs
2. Clone a manager role, assign it to all or some orgs
3. Create a user, assign the role to it, assign it to one or more of the role's orgs
4. Log in as the user or impersonate, navigate to Monitor > Tasks

Actual results:
No tasks listed, above errors shown

Expected results:
Tasks viewed as exoected

Additional info:
Seems to be related to org assignment in cloned role, using the default manager role or using a cloned role with no org assigned doesn't produce this issue

Comment 1 Peter Ondrejka 2021-01-27 15:31:57 UTC
Created attachment 1751293 [details]
prodlog

Comment 2 Peter Ondrejka 2021-01-27 15:32:36 UTC
Created attachment 1751294 [details]
prodlog2

Comment 3 Adam Ruzicka 2021-02-01 09:40:01 UTC
Alternative steps to reproduce:

1) run foreman-rake console
2) Enter ForemanTasks::Task.search_for("organization_id ^ (1)").first

Note:
Searching by taxonomies on tasks still uses a custom external method, which doesn't handle queries with IN well.

Comment 4 Peter Ondrejka 2021-02-01 10:54:47 UTC
Hello, on Satellite 6.8.3:

~]# foreman-rake console
ForemanTasks::Task.search_for("organization_id ^ (1)").first
Loading production environment (Rails 6.0.3.1)
irb(main):001:0> ForemanTasks::Task.search_for("organization_id ^ (1)").first
Traceback (most recent call last):
        2: from lib/tasks/console.rake:5:in `block in <top (required)>'
        1: from (irb):1
ActiveRecord::StatementInvalid (PG::SyntaxError: ERROR:  syntax error at or near "'1'")
LINE 3: ...foreman_tasks_locks_taxonomyb72f2d.resource_id IN '1' OR for...
                                                             ^

Comment 5 Bryan Kearney 2021-02-10 12:03:05 UTC
Moving this bug to POST for triage into Satellite since the upstream issue https://projects.theforeman.org/issues/31773 has been resolved.

Comment 6 Adam Ruzicka 2021-02-11 08:49:43 UTC
Requesting 6.9.0+ since this blocks https://bugzilla.redhat.com/show_bug.cgi?id=1741943

Comment 9 Peter Ondrejka 2021-03-01 14:44:59 UTC
Verified on Satellite 6.9 snap 15

Comment 10 Peter Ondrejka 2021-03-01 15:16:32 UTC
Sorry, taking back comment#9, the verification steps from comment#3 work well, though when using original steps (cloned role with multiple orgs and user with some of those orgs) the issue persists with the following in the production log:

PG::InvalidTextRepresentation: ERROR:  invalid input syntax for type integer: "1,3,5,7,6,4"
 ab598f13 | LINE 7: ...oreman_tasks_locks_taxonomyc9ce1d.resource_id IN ('1,3,5,7,6...

Comment 11 Peter Ondrejka 2021-03-08 12:26:50 UTC
Hi Zach, I still see tfm-rubygem-foreman-tasks-3.0.4 on snap 16, did we miss a cherry-pick?

Comment 12 Peter Ondrejka 2021-03-12 09:37:43 UTC
Verified on Satellite 6.9 snap 17

Comment 15 errata-xmlrpc 2021-04-21 13:10:30 UTC
Since the problem described in this bug report should be
resolved in a recent advisory, it has been closed with a
resolution of ERRATA.

For information on the advisory (Moderate: Satellite 6.9 Release), and where to find the updated
files, follow the link below.

If the solution does not work for you, open a new bug report.

https://access.redhat.com/errata/RHSA-2021:1313