Note: This bug is displayed in read-only format because the product is no longer active in Red Hat Bugzilla.
Red Hat Satellite engineering is moving the tracking of its product development work on Satellite to Red Hat Jira (issues.redhat.com). If you're a Red Hat customer, please continue to file support cases via the Red Hat customer portal. If you're not, please head to the "Satellite project" in Red Hat Jira and file new tickets here. Individual Bugzilla bugs will be migrated starting at the end of May. If you cannot log in to RH Jira, please consult article #7032570. That failing, please send an e-mail to the RH Jira admins at rh-issues@redhat.com to troubleshoot your issue as a user management inquiry. The email creates a ServiceNow ticket with Red Hat. Individual Bugzilla bugs that are migrated will be moved to status "CLOSED", resolution "MIGRATED", and set with "MigratedToJIRA" in "Keywords". The link to the successor Jira issue will be found under "Links", have a little "two-footprint" icon next to it, and direct you to the "Satellite project" in Red Hat Jira (issue links are of type "https://issues.redhat.com/browse/SAT-XXXX", where "X" is a digit). This same link will be available in a blue banner at the top of the page informing you that that bug has been migrated.

Bug 1375788

Summary: API search on resource that has many organizations with organization_id fails with SQL error
Product: Red Hat Satellite Reporter: Mihir Lele <mlele>
Component: Organizations and LocationsAssignee: Tomer Brisker <tbrisker>
Status: CLOSED ERRATA QA Contact: Peter Ondrejka <pondrejk>
Severity: high Docs Contact:
Priority: high    
Version: 6.2.0CC: andrew.schofield, bbuckingham, bkearney, egolov, inecas, jcallaha, kabbott, mhulan, mowens, oshtaier, sabnave, sshtein, szadok, tbrisker
Target Milestone: UnspecifiedKeywords: PrioBumpPM, Triaged
Target Release: Unused   
Hardware: x86_64   
OS: Linux   
Whiteboard:
Fixed In Version: foreman-1.15.6.9 Doc Type: If docs needed, set a value
Doc Text:
Story Points: ---
Clone Of: Environment:
Last Closed: 2018-02-21 16:54:17 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: 1479962    

Description Mihir Lele 2016-09-14 04:19:05 UTC
Description of problem:

API get on ptables with organization ID fails with SQL error

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


How reproducible: Always


Steps to Reproduce:
1. Search for ptables works correctly, but throws an error when used with organization id.     
2.https://satellite.example.com/api/v2/ptables?search=FreeBSD&organization_id=1


Actual results:     api output displayed with error

Expected results:   Should display the output of the searched string in ptables


Additional info:

Actual error:

{
  "error": {"message":"PG::Error: ERROR:  missing FROM-clause entry for table \"organizations_templates\"\nLINE 1: ... t1_r9, \"taxonomies\".\"katello_default\" AS t1_r10, \"organizat...\n                                                             ^\n: SELECT \"templates\".\"id\" AS t0_r0, \"templates\".\"name\" AS t0_r1, \"templates\".\"template\" AS t0_r2, \"templates\".\"snippet\" AS t0_r3, \"templates\".\"template_kind_id\" AS t0_r4, \"templates\".\"created_at\" AS t0_r5, \"templates\".\"updated_at\" AS t0_r6, \"templates\".\"locked\" AS t0_r7, \"templates\".\"default\" AS t0_r8, \"templates\".\"vendor\" AS t0_r9, \"templates\".\"type\" AS t0_r10, \"templates\".\"os_family\" AS t0_r11, \"templates\".\"job_category\" AS t0_r12, \"templates\".\"provider_type\" AS t0_r13, \"templates\".\"description_format\" AS t0_r14, \"taxonomies\".\"id\" AS t1_r0, \"taxonomies\".\"name\" AS t1_r1, \"taxonomies\".\"type\" AS t1_r2, \"taxonomies\".\"created_at\" AS t1_r3, \"taxonomies\".\"updated_at\" AS t1_r4, \"taxonomies\".\"ignore_types\" AS t1_r5, \"taxonomies\".\"description\" AS t1_r6, \"taxonomies\".\"label\" AS t1_r7, \"taxonomies\".\"ancestry\" AS t1_r8, \"taxonomies\".\"title\" AS t1_r9, \"taxonomies\".\"katello_default\" AS t1_r10, \"organizations_templates\".\"id\" AS t2_r0, \"organizations_templates\".\"name\" AS t2_r1, \"organizations_templates\".\"type\" AS t2_r2, \"organizations_templates\".\"created_at\" AS t2_r3, \"organizations_templates\".\"updated_at\" AS t2_r4, \"organizations_templates\".\"ignore_types\" AS t2_r5, \"organizations_templates\".\"description\" AS t2_r6, \"organizations_templates\".\"label\" AS t2_r7, \"organizations_templates\".\"ancestry\" AS t2_r8, \"organizations_templates\".\"title\" AS t2_r9, \"organizations_templates\".\"katello_default\" AS t2_r10 FROM \"templates\" INNER JOIN \"taxable_taxonomies\" ON \"taxable_taxonomies\".\"taxable_id\" = \"templates\".\"id\" AND \"taxable_taxonomies\".\"taxable_type\" = 'Ptable' INNER JOIN \"taxonomies\" ON \"taxonomies\".\"id\" = \"taxable_taxonomies\".\"taxonomy_id\" AND \"taxonomies\".\"type\" = 'Organization' LEFT OUTER JOIN \"taxable_taxonomies\" \"taxable_taxonomies_templates_join\" ON \"taxable_taxonomies_templates_join\".\"taxable_id\" = \"templates\".\"id\" AND \"taxable_taxonomies_templates_join\".\"taxable_type\" = 'Ptable' LEFT OUTER JOIN \"taxonomies\" \"locations_templates\" ON \"locations_templates\".\"id\" = \"taxable_taxonomies_templates_join\".\"taxonomy_id\" AND \"locations_templates\".\"type\" = 'Location' WHERE \"templates\".\"type\" IN ('Ptable') AND \"taxonomies\".\"type\" IN ('Organization') AND ((\"taxonomies\".\"id\" = 1 OR \"taxonomies\".\"title\" = '1')) AND ((\"taxonomies\".\"name\" ILIKE '%FreeBSD%' OR \"taxonomies\".\"name\" ILIKE '%FreeBSD%' OR \"templates\".\"name\" ILIKE '%FreeBSD%' OR \"templates\".\"template\" ILIKE '%FreeBSD%' OR \"templates\".\"template\" ILIKE '%FreeBSD%' OR \"templates\".\"os_family\" ILIKE '%FreeBSD%')) AND \"templates\".\"id\" IN (58)  ORDER BY \"templates\".\"name\" ASC NULLS FIRST"}
}

Comment 3 Bryan Kearney 2016-10-07 16:24:07 UTC
Created redmine issue http://projects.theforeman.org/issues/16835 from this bug

Comment 4 Bryan Kearney 2016-10-10 08:09:11 UTC
Upstream bug component is API

Comment 5 Shimon Shtein 2016-10-13 13:47:10 UTC
Fails in latest Foreman too. One clarification: the organization should be an existing one.

Comment 6 Ivan Necas 2016-11-23 12:01:59 UTC
Since the category changed, putting devel_triaged back to ?

Comment 10 Satellite Program 2017-10-30 14:11:03 UTC
Upstream bug assigned to tbrisker

Comment 11 Satellite Program 2017-10-30 14:11:08 UTC
Upstream bug assigned to tbrisker

Comment 12 Satellite Program 2017-10-31 12:13:08 UTC
Moving this bug to POST for triage into Satellite 6 since the upstream issue http://projects.theforeman.org/issues/16835 has been resolved.

Comment 13 Peter Ondrejka 2017-11-20 13:31:53 UTC
Verified on Sat 6.3 snap 25, querying entities with search expression + limiting to organization responds as expected now, e.g.:

.../api/v2/job_templates?search=Errata&organization_id=1

{

    "total": 14,
    "subtotal": 1,
    "page": 1,
    "per_page": 20,
    "search": "Errata",
    "sort": {
        "by": null,
        "order": null
    },
    "results": [
        {
            "id": 109,
            "name": "Install Errata - Katello SSH Default",
            "job_category": "Katello",
            "provider_type": "SSH",
            "snippet": false,
            "description_format": "Install errata %{errata}"
        }
    ]

}

Comment 14 Satellite Program 2018-02-21 16:54:17 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, 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-2018:0336