Data explorer group report - parameter bug

AI-generated summary

Data Explorer Group Report - Parameter Bug

A bug was reported by piffy in the Data Explorer plugin where exposing queries to groups caused an error when updating parameter values. The error occurred when trying to enter text into the username box or changing the min_days value, resulting in an “Uncaught TypeError: t is undefined” error.

piffy provided a detailed report of the issue, including screenshots and a link to the problematic code. Isaac acknowledged the report and asked for the query that was causing the issue, which piffy provided.

JammyDodger offered an alternative solution using the user_id parameter, which provides an auto-complete feature.

Isaac later confirmed that the issue was fixed, and piffy verified that the fix worked, expressing gratitude on behalf of their users who appreciate this feature.

I just updated to the latest version of the Data Explorer before posting this and I can confirm this issue is still present for me.

On the data explorer 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.

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

The error seems to be caused by the request being sent (here I am showing the network inspector on firefox):
image

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:

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.

4 Likes

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:

5 Likes
--[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 on (official plugins only) and have the same issue.

1 Like

Thank you, I will take a look.

2 Likes

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:

-- [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

5 Likes

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

3 Likes

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

4 Likes

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

3 Likes