Red Hat Bugzilla – Bug 1151240
Some API URLs emit a list of IDs, and others emit a list of hashes.
Last modified: 2017-02-23 15:52:55 EST
Description of problem: Some API responses contain a list of IDs, and others contain a list of hashes. For example, a GET request to `/gpgkeys/:id` returns data in this format: {u'name': u'foo', u'organization': {u'name': u'ACME', u'label': '...'}} No organization ID is listed. This means that it is impossible to discover what organization this GPG key belongs to except by issuing a follow-up search to the `/organizations` URL (and hopefully coming up with only one result). As a second example, a GET request to `/architectures/:id` returns data in this format: { u'name': u'i386', u'operatingsystems': [ {u'id': 1, u'name': u'rhel65'}, {u'id': 2, u'name': u'rhel7'}, ] } This is awkward. In this case, the client can compile a list of associated operating systems by iterating through the returned hashes and fetching through their IDs. It is much easier to deal with a straight list of IDs: {u'name': u'i386', u'operatingsystem_ids': [1, 2]} The API should return either an ID or a list of IDs for all foreign key relationships. Client code can be simple and straightforward if a list of IDs is returned. Version-Release number of selected component (if applicable): This has been tested against multiple versions of Satellite. Most recently, this has been tested against a system running Satellite 6.0.4 with the following software installed: * candlepin-0.9.23-1.el7.noarch * candlepin-common-1.0.1-1.el7.noarch * candlepin-guice-3.0-2_redhat_1.el7.noarch * candlepin-scl-1-5.el7.noarch * candlepin-scl-quartz-2.1.5-6.el7.noarch * candlepin-scl-rhino-1.7R3-3.el7.noarch * candlepin-scl-runtime-1-5.el7.noarch * candlepin-selinux-0.9.23-1.el7.noarch * candlepin-tomcat-0.9.23-1.el7.noarch * elasticsearch-0.90.10-6.el7sat.noarch * foreman-1.6.0.46-1.el7sat.noarch * foreman-compute-1.6.0.46-1.el7sat.noarch * foreman-gce-1.6.0.46-1.el7sat.noarch * foreman-libvirt-1.6.0.46-1.el7sat.noarch * foreman-ovirt-1.6.0.46-1.el7sat.noarch * foreman-postgresql-1.6.0.46-1.el7sat.noarch * foreman-proxy-1.6.0.30-1.el7sat.noarch * foreman-selinux-1.6.0.14-1.el7sat.noarch * foreman-vmware-1.6.0.46-1.el7sat.noarch * katello-1.5.0-30.el7sat.noarch * katello-certs-tools-1.5.6-1.el7sat.noarch * katello-default-ca-1.0-1.noarch * katello-installer-0.0.64-1.el7sat.noarch * katello-server-ca-1.0-1.noarch * openldap-2.4.39-3.el7.x86_64 * pulp-katello-0.3-4.el7sat.noarch * pulp-nodes-common-2.4.1-0.7.beta.el7sat.noarch * pulp-nodes-parent-2.4.1-0.7.beta.el7sat.noarch * pulp-puppet-plugins-2.4.1-0.7.beta.el7sat.noarch * pulp-puppet-tools-2.4.1-0.7.beta.el7sat.noarch * pulp-rpm-plugins-2.4.1-0.7.beta.el7sat.noarch * pulp-selinux-2.4.1-0.7.beta.el7sat.noarch * pulp-server-2.4.1-0.7.beta.el7sat.noarch * python-ldap-2.4.6-6.el7.x86_64 * ruby193-rubygem-net-ldap-0.3.1-3.el7sat.noarch * ruby193-rubygem-runcible-1.1.0-2.el7sat.noarch How reproducible: 100%, but the exact response of each API URL varies. Steps to Reproduce: See the "Description of problem" section of this bug report. Actual results: A hash or list of hashes that may or may not contain IDs. Expected results: An ID or list of IDs. Additional info: n/a
A test which targets this bug for one of the API URLs has been submitted. See: https://github.com/SatelliteQE/robottelo/pull/1545
This bug report claims that "Client code can be simple and straightforward if a list of IDs is returned." For an example of the workarounds that are required when hashes are returned, search for the phrase "1151240" in this file: https://github.com/SatelliteQE/robottelo/blob/master/robottelo/entities.py Searching for that phrase may not work until pull request #1545 is merged.
*** Bug 1122267 has been marked as a duplicate of this bug. ***
Since this issue was entered in Red Hat Bugzilla, the release flag has been set to ? to ensure that it is properly evaluated for this release.
The first example of gpgkeys is the problem here, it should include the ID in the output for an individual organisation. The latter format may be standardised in APIv3 in the future.
I'm happy to hear that this may be included in APIv3.
Should be resolved as of https://github.com/Katello/katello/commit/b761e5acb522892d0969d1f2ad3db9e060dadf74#diff-9f471efc5c9974e05e8e509e1956715fL3
Tested against Satellite-6.1.0-RHEL-6-20150303.0 and Satellite-6.1.0-RHEL-7-20150303.0.
This bug is slated to be released with Satellite 6.1.
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-2015:1592