Open evgeni opened 3 months ago
So to understand this correctly, the module is failing under the right circumstances, but for the wrong reason, right?
To pick up your idea: Can we pass the required
flag from the foreman_spec
to find_resource_by
and then change that to start with
def find_resource_by(self, resource, search_field, value, required=False, **kwargs):
if not value:
if required:
raise WhateverRequiredEntityNotSpecifiedError()
return NoEntity
...
So to understand this correctly, the module is failing under the right circumstances, but for the wrong reason, right?
Yeah. Most importantly, it gives an ugly stack trace instead of erroring with "couldn't find resource X".
Can we pass the required flag from the foreman_spec to find_resource_by and then change that to start with
Yes, that's roughly the direction I was heading.
Actually, I think this should be sufficient:
def find_resource_by(self, resource, search_field, value, required=False, **kwargs):
if not value and not required:
return NoEntity
…
As the rest of the code will already correctly error when nothing was found.
Right. My line of thought was "Nothing found." is a different complaint than "You didn't specify a required thing.".
Yeah… but they did specify it ("" is a specification), so imho the error "nothing found with name ''" is the correct one here.
Fair. Can we spare a lookup request when we already know that "" will not find us anything?
Maybe? ;-)
SUMMARY
Because of the "empty string is special to unset things" logic introduced in f50bd16e9bf0dfe06762785434f3fd3d7e0c05f6, we do not immediately fail when such an input is provided, which leads to errors in the code later on that relies on the fact that the entity was properly found.
we probably should just not apply the "empty string to unset" logic to parameters that are set as
required=True
(likecontent_view
in thecontent_view_version
module, which the example below uses).ISSUE TYPE
ANSIBLE VERSION
all
COLLECTION VERSION
since f50bd16e9bf0dfe06762785434f3fd3d7e0c05f6
KATELLO/FOREMAN VERSION
all
STEPS TO REPRODUCE
EXPECTED RESULTS
ACTUAL RESULTS