nailgun icon indicating copy to clipboard operation
nailgun copied to clipboard

Tweak the helper methods

Open Ichimonji10 opened this issue 9 years ago • 1 comments

It's really easy to call a helper and pass in the wrong kind of arguments. For example, it's really tempting to write this:

content_view.publish({'content_view_id': 5})

But that's totally wrong. That's the same as:

content_view.publish(synchronous={'content_view_id': 5})

Let's make the synchronous argument a keyword argument. This is a breaking change, which sucks. But thankfully, it's a fairly straightforward breaking change to deal with, and it may help prevent many mis-uses of the helper methods. We're changing method signatures from this:

my_method(synchronous=True, **kwargs)

To this:

my_method(**kwargs)

At this point, all of the helper methods would have exactly two custom kwargs: synchronous and timeout. (Assuming #218 is implemented.)

A second possible change is to make each of the helper methods have a signature that matches the underlying method being called. As an example, the ContentView.publish method calls post. If both the first and second suggestions are accepted, it changes like so:

publish(synchronous=True, **kwargs)
publish(**kwargs)
publish(data=None, json=None, **kwargs)

Thankfully, this second proposed change is not breaking. Given that the Satellite/Foreman API deals exclusively with JSON, I'm not sure how much of an improvement this second change would yield for clients. But it's something to consider.

Ichimonji10 avatar Sep 15 '15 20:09 Ichimonji10

:+1:

elyezer avatar Sep 24 '15 18:09 elyezer