Syntax for Data Explorer params in Automation

AI-generated summary

The discussion revolves around the Syntax for Data Explorer params in Automation. Ann Campbell is trying to automate a Data Explorer query that accepts a ‘group_name’ parameter, but is struggling with the syntax. Arkshine reproduces the issue and investigates the code, finding a potential problem with how parameters are transformed.

Akshine proposes a possible solution, and Ted Johansson confirms there was a bug and fixes it in a pull request. With the bug fixed, Ted Johansson explains that currently, there is no connection between the recipient list and the report parameters, so setting up one automation per group is required.

Ann Campbell and Ted Johansson discuss the need for a foreach feature to iterate over a set of groups, which would be convenient for sites with many groups. Ted Johansson notes down the request but cannot provide a timeline for its implementation. Sam Saffron appreciates the debugging efforts, and Ted Johansson is grateful for Arkshine’s investigation.

I have a Data Explorer query that accepts a ‘group_name’ parameter

I would like to automate running it for each relevant group and sending the group the results once a week.

But for the life of me, I cannot figure out the syntax to use for the parameter. Here’s what I’m presented for that in a brand new automation:

I find this… unhelpful.

I’ve tried several variations here. When I don’t get an error from my attempts (found in the error logs), I seem to get nothing at all.

If I use a query with no parameters, it runs like greased lightning. How do I make it work for queries that do need parameters?

2 Likes

I can reproduce the issue as well.

In your example, let’s say you want to check the moderators and admins groups, you are supposed to have:

key: group_name
value: moderators,admins


Technical stuff to help, don’t mind me. :smile:
I tried to understand looking at the code, and I think there is an issue here:

The params are transformed before run_query is called.
Let’s say you have this original value:
[{"key":"group_names","value":"admins,moderators"}]
The transformed value will be:
{{"key"=>"group_names", "value"=>"admins,moderators"}=>nil}

However, cast_params seems to expect {"group_names"=>"admins,moderators"}

I tried to test this naive change, and the params worked.

def self.params_to_hash(query_params)
  params = JSON.parse(query_params)
  params_hash = {}

  params.each do |param|
    key = param["key"]
    value = param["value"]
    params_hash[key] = value
  end

  params_hash
end
7 Likes

wow thanks for the debugging here :hugs: we will have a look at this in the upcoming week.

5 Likes

That’s some fantastic spelunking, @Arkshine! :slightly_smiling_face:

I’m looking into this now. When I read the original code I get the impression that it expects the parameters to be an array of arrays, so I’m a bit weary of just throwing the existing stuff out. Will try to figure out when this might happen.

Will post here when I find something.

1 Like

There was indeed a bug here, and partly thanks to the investigation of @Arkshine, it was relatively easy to fix:

https://github.com/discourse/discourse-data-explorer/pull/363

This has been merged already, so once your site has been deployed you should be unblocked @ganncamp.

If I understand correctly, you want an automation that is a one-to-one mapping between a group and its report? (I.e. group_a receives a report with group_a data, etc.)

There is (currently) no connection between the recipient list and the report parameters, so to accomplish that you’d need to set up one automation per group. In this case you might want to change the parameter to group_id.

3 Likes

Great news @ted!

Yes, being able to foreach a set of groups was going to be my next request :smile:

3 Likes

This does indeed seem like a convenient thing to have, especially for sites with lots and lots of groups. I’ll note down the request, but I can’t say when we’ll get to it. :folded_hands:

3 Likes

This topic was automatically closed 3 days after the last reply. New replies are no longer allowed.