# Data explorer group report - parameter bug

**URL:** https://meta.discourse.org/t/data-explorer-group-report-parameter-bug/249525
**Category:** Bug
**Tags:** data-explorer
**Created:** [December 20, 2022, 9:30pm UTC](https://meta.discourse.org/t/data-explorer-group-report-parameter-bug/249525 "2022-12-20T21:30:20Z")
**Posts on this page:** 9
**Page:** 1

<div class="post-metadata">

### Author: ![piffy](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/piffy/32/254198_2.png) [@piffy](https://meta.discourse.org/u/piffy)
#### Post date: [December 20, 2022, 9:30pm UTC](https://meta.discourse.org/t/data-explorer-group-report-parameter-bug/249525/1 "2022-12-20T21:30:20Z")

</div>

I just updated to the latest version of the [Data Explorer](https://meta.discourse.org/t/32566?silent=true) before posting this and I can confirm this issue is still present for me.

On the [data explorer](https://meta.discourse.org/t/32566?silent=true) plugin there’s a feature that lets you expose queries to groups. I have done this for the query that counts consecutive days visited because I have users desperate to know how close they are to the xxx days visited badges.

 ![image](https://global.discourse-cdn.com/meta/original/4X/a/9/4/a940e83234e5e0e55d9527fa3aa58d69046bae41.png)

This was working until recently. Now I get this error.

 ![image](https://global.discourse-cdn.com/meta/original/4X/6/7/5/675259201cc838472f478333868e0070df81459b.png)

The error seems to be caused by the request being sent (here I am showing the network inspector on firefox):  
 ![image](https://global.discourse-cdn.com/meta/original/4X/9/f/8/9f84e614cd37309df658275eabb4d7e338707986.png)

It appears to not be updating the parameter values as they are being entered (`username=null`, `min_days=10` are the default parameters when you load the page). The console also gives an error “Uncaught TypeError: t is undefined” when either entering text into the `username` box or changing the `min_days` value. This line is throwing the error:

> <https://github.com/discourse/discourse-data-explorer/blob/8028b9f16a33553bd3a6e1955ced98f15843cb77/assets/javascripts/discourse/components/param-input.js#L170>

This is the best I can do of tracing the issue short of forking the repo and debugging each line. Just wanted to report the issue and also curious if others have the same problem.

---

<div class="post-metadata">

### Author: ![isaac](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/isaac/32/235758_2.png) [@isaac](https://meta.discourse.org/u/isaac)
#### Post date: [December 20, 2022, 9:58pm UTC](https://meta.discourse.org/t/data-explorer-group-report-parameter-bug/249525/3 "2022-12-20T21:58:02Z")

</div>

Thanks @piffy for the report. We have recently made some changes to data-explorer plugin so this could very well be valid. I have tested multiple queries with a usernames input and have not ran into the issue linked in OP. Could you drop your query here that I could test it out?

Thanks :slight_smile:

---

<div class="post-metadata">

### Author: ![piffy](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/piffy/32/254198_2.png) [@piffy](https://meta.discourse.org/u/piffy)
#### Post date: [December 20, 2022, 10:02pm UTC](https://meta.discourse.org/t/data-explorer-group-report-parameter-bug/249525/4 "2022-12-20T22:02:25Z")

</div>

```plaintext
--[params]
-- string :username
-- int :min_days = 10

WITH consecutive_visits AS (
  SELECT user_id,
       visited_at,
       -- The value of s will be the same for each group of consecutive days
       visited_at - (DENSE_RANK() OVER (PARTITION BY user_id ORDER BY visited_at))::int s
    FROM user_visits
    WHERE user_id = (SELECT id FROM users WHERE username = :username)
)

SELECT
MIN(visited_at) period_start,
COUNT(*) AS consecutive_days,
MAX(visited_at) period_end
FROM consecutive_visits
GROUP BY user_id, s
HAVING COUNT(*) >= :min_days
ORDER BY period_start DESC

```

I tried with [safe mode](https://meta.discourse.org/t/53504?silent=true) on (official plugins only) and have the same issue.

---

<div class="post-metadata">

### Author: ![isaac](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/isaac/32/235758_2.png) [@isaac](https://meta.discourse.org/u/isaac)
#### Post date: [December 20, 2022, 10:07pm UTC](https://meta.discourse.org/t/data-explorer-group-report-parameter-bug/249525/5 "2022-12-20T22:07:56Z")

</div>

Thank you, I will take a look.

---

<div class="post-metadata">

### Author: ![JammyDodger](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/jammydodger/32/254611_2.png) [@JammyDodger](https://meta.discourse.org/u/JammyDodger)
#### Post date: [December 21, 2022, 9:53am UTC](https://meta.discourse.org/t/data-explorer-group-report-parameter-bug/249525/7 "2022-12-21T09:53:16Z")

</div>

As a fun extra tip while Isaac takes a look at that, you can also use the `user_id` parameter to get a swish auto-complete parameter box. eg:

```plaintext
-- [params]
-- user_id :user
-- int :min_days = 10

WITH consecutive_visits AS (
  SELECT user_id,
       visited_at,
       -- The value of s will be the same for each group of consecutive days
       visited_at - (DENSE_RANK() OVER (PARTITION BY user_id ORDER BY visited_at))::int s
    FROM user_visits
    WHERE user_id = :user
)

SELECT
MIN(visited_at) period_start,
COUNT(*) AS consecutive_days,
MAX(visited_at) period_end
FROM consecutive_visits
GROUP BY user_id, s
HAVING COUNT(*) >= :min_days
ORDER BY period_start DESC

```

---

<div class="post-metadata">

### Author: ![piffy](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/piffy/32/254198_2.png) [@piffy](https://meta.discourse.org/u/piffy)
#### Post date: [December 21, 2022, 5:55pm UTC](https://meta.discourse.org/t/data-explorer-group-report-parameter-bug/249525/8 "2022-12-21T17:55:34Z")

</div>

Thanks, good to know! Makes a lot more sense than a free-form text box

---

<div class="post-metadata">

### Author: ![isaac](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/isaac/32/235758_2.png) [@isaac](https://meta.discourse.org/u/isaac)
#### Post date: [December 28, 2022, 5:49pm UTC](https://meta.discourse.org/t/data-explorer-group-report-parameter-bug/249525/9 "2022-12-28T17:49:50Z")

</div>

Sorry for the delay @piffy. This should be fixed now :slight_smile:

---

<div class="post-metadata">

### Author: ![piffy](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/piffy/32/254198_2.png) [@piffy](https://meta.discourse.org/u/piffy)
#### Post date: [December 28, 2022, 6:59pm UTC](https://meta.discourse.org/t/data-explorer-group-report-parameter-bug/249525/10 "2022-12-28T18:59:14Z")

</div>

It works, thanks so much! My users really appreciate this feature

---

<div class="post-metadata">

### Author: ![isaac](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/isaac/32/235758_2.png) [@isaac](https://meta.discourse.org/u/isaac)
#### Post date: [December 28, 2022, 7:00pm UTC](https://meta.discourse.org/t/data-explorer-group-report-parameter-bug/249525/11 "2022-12-28T19:00:15Z")

</div>


