nailgun icon indicating copy to clipboard operation
nailgun copied to clipboard

Search is inconsistent accross entities

Open Fobhep opened this issue 7 years ago • 2 comments

While playing around we (@mdellweg and me) got some rather inconsistent results, across entities.

len(Organization().search())
>>> 3 correct

len(Organization(id=1).search())
>>> 3 wrong

len(Organization().search(query={'search':'id="1" '}))
>>> 1  correct

len(Organization().search(query={'search':'name="ATIX" '}))
>>> 1 correct

len(Organization(name="ATIX").search())
>>> 3 wrong

Location shows the same behavior.

len(LifecycleEnvironment().search())
>>> 6 correct

len(LifecycleEnvironment(id=1).search())
>>> 6 wrong

len(LifecycleEnvironment().search(query={'search':'id="1"'}))
>>> 6 wrong

len(LifecycleEnvironment(name="Testing").search())
>>> 1 correct

len(LifecycleEnvironment().search(query={'search':'name="Testing"'}))
>>> 1 correct

Conclusion: For Location and Organization searching works only with the "rather pointless example" from the documentation

On the other hand for the LifecycleEnvironment the search for "name" works in both ways, for "id" however never. This contradicts the description in the documentation.

@Ichimonji10 could you comment on this, since you seem familiar with the search functionality.

Fobhep avatar Jul 06 '17 15:07 Fobhep

I'm not a great person to ask. I haven't worked with nailgun in about two years.

The fundamental problem is that Satellite's APIs (and the APIs of its constituent parts, like Katello) are inconsistent. Nailgun tries to hide these inconsistencies by constructing search requests in one particular way by default and then making exceptions as necessary. Unfortunately, the work-arounds aren't comprehensive, and the underlying issues bubble up. Even worse, the searches that Satellite (and Katello, etc) accept sometimes change in new versions. Plus, Satellite frequently ignores invalid search parameters instead of returning some kind of error or warning. (At least, that was the case when I used it.)

Entity().search_payload(...) shows the search query that's constructed. If an incorrect search query is being constructed, solutions include:

  • Fix how nailgun constructs search queries.
  • Don't use nailgun.

Ichimonji10 avatar Jul 06 '17 16:07 Ichimonji10

One thing to note here is that the Organization/Location (i.e. Taxonomy) search is different than any other Foreman/Katello model; I'm not sure why it is, but it's definitely inconvenient when consuming the API. Regardless, the inconsistencies noted above are inconsistencies in the Foreman/Katello API, not NailGun. If you'd like to open an issue, there would be more discussion from the wider development group. I'd certainly +1 any changes to make the API more consistent.

One other thing: why would you search with id? You should use the read() method instead. i.e. LifecycleEnvironment(id=1).read() works just fine.

akofink avatar Jul 07 '17 13:07 akofink