Skip to content

Using kwargs in create_XX functions to allow passing any parameters in the payload #14

@benoitscherrer

Description

@benoitscherrer

For example, for create_query:

It is probably good that the payload always contains a few parameters (e.g., data_source_id, name, etc...), but what about all other potential (and useful) parameters? For example tags, etc, Using kwargs would be a great way to make your API much more general.

For example for create_query:

def create_query(self, ds_id: int, name: str, qry: str, desc: str="", with_results: bool=True, **kwargs):
        payload = {
            "data_source_id": ds_id,
            "name": name,
            "query": qry,
            "description": desc,
            **kwargs
        }

        res = self.post('queries', payload)

        if with_results:
            self.generate_query_results(ds_id, qry)

        return res

Then you can use it with

redash.create_query(1, "my query", "select 1 from table", "description", with_results=False, tags=["mytag"], options={} )

If you remove options (i would) that would be a breaking change, so that's probably your decision.
But all that would be very easy to add that to all create_XXX functions.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions