explorerhq / explorerhq/sql-explorer
Parameterized query downloads empty CSV; same query in Playground is fine
- Dominant language
- Python
- Stars
- 2.9k
- Forks
- 373
- PR merge metrics
- No merged PRs in 30d
Description
Hi all,
This issue doesn't appear to manifest in in 4.x, or 4.3.0 specifically. However, the 4.x series isn't quite ready for us yet…

…in terms of how the query parameters are rendered, and that's fine. It's just CSS, and I'm sure that'll be resolved eventually. On top of that, though, we've spent a bit of time customizing the templates in such a way that it didn't carry over with 4.x, so I'm reluctant to upgrade and have to re-do all that.
That said… if this is a `wontfix` kind of an issue, I respect that.
I checked to see if this had come up in some other issue, or in a PR or discussion, no dice.
## Issue description
One out of many of [parameterized queries](https://django-sql-explorer.readthedocs.io/en/latest/features.html#parameterized-queries) (below) generates an "empty" CSV containing only the headers, and JSON containing only the outer square brackets. However, the generated SQL, copied from the query log into a new Playground works fine; the CSV is populated with data as expected.
Here's the query that triggers the behavior, lightly sanitized.
-- doing a SELECT on a SELECT was the only way I could figure out how
-- to get the DATEDIFF columns to show up
SELECT eid AS id_link,
short_name,
project_name,
project_lead,
extra_details,
note,
updated_at,
updated_days_ago,
created_at,
created_days_ago,
submission_date,
submitted_days_ago,
received_date,
received_days_ago,
read1_file_path,
read1_file_checksum,
read1_file_header,
read2_file_path,
read2_file_checksum
FROM
(SELECT e.id AS eid,
shortname(e.id) AS short_name,
e.extra_details AS extra_details,
e.note AS note,
et.type AS exp_type,
p.name AS project_name,
lm.name AS project_lead,
e.updated_at AS updated_at,
DATEDIFF(now(), e.updated_at) AS updated_days_ago,
e.created_at AS created_at,
DATEDIFF(now(), e.created_at) AS created_days_ago,
e.submission_date AS submission_date,
DATEDIFF(now(), e.submission_date) AS submitted_days_ago,
e.received_date AS received_date,
DATEDIFF(now(), e.received_date) AS received_days_ago,
e.read1_file_path AS read1_file_path,
e.read1_file_checksum AS read1_file_checksum,
e.read1_file_header AS read1_file_header,
e.read2_file_path AS read2_file_path,
e.read2_file_checksum AS read2_file_checksum
FROM server_experiment e,
server_project p,
server_experimenttype et,
server_labmember lm
WHERE e.project_id = p.id
AND e.experiment_type_id = et.id
AND e.lead_id = lm.id) t
WHERE project_name LIKE "%$$pname|Proj. name$$%"
AND project_lead LIKE "%$$lead|Proj. lead$$%"
AND exp_type LIKE "%$$etype|Exp. type$$%"
AND short_name LIKE "%$$shortname|Shortname$$%"
AND extra_details LIKE "%$$details|Extra details$$%"
AND note LIKE "%$$note|Note$$%"
AND (
read1_file_path LIKE "%$$filename|Filename (R1 or R2)$$%%"
OR read2_file_path LIKE "%$$filename|Filename (R1 or R2)$$%%"
)
AND submission_date LIKE "$$submission_date|Submission date:%$$"
AND received_date LIKE "$$received_date|Received date:%$$"
AND (
submitted_days_ago < "$$submitted_days_ago|Submitted within (days):10000$$"
OR submitted_days_ago IS NULL
)
AND (
received_days_ago < "$$received_days_ago|Received within (days):10000$$"
OR received_days_ago IS NULL
)
AND (
created_days_ago < "$$created_days_ago|Created within (days):10000$$"
OR created_days_ago IS NULL
)
AND (
updated_days_ago < "$$updated_days_ago|Updated within (days):10000$$"
OR updated_days_ago IS NULL
)
ORDER BY id_link ASC;
## Workaround
Open the most recent query from the query logs in Playground, export the CSV from there:
* Run the query as normal
* Click "Logs" (`explorer/logs`, relative to your Django app)
* Click "Open" in the "Playground" column for the most recent entry
* Re-run the query and click **Download** → **CSV**
## Asking for advice for troubleshooting
I'm not asking for SQL advice, just including the query in case it's insightful. Similar queries (excepting the `SELECT` from a `SELECT` part) generate CSVs just fine, and nothing like a Python traceback appears in the server logs.
More asking for advice about where to look to troubleshoot this.
We're invested enough in 3.2.x at this point that I may want to devote time to fixing the issue in that old branch—no promises, though—if you're willing to entertain patches to keep it on life support for a while longer.
Contributor guide
No contributing guide indexed for this repository
Assessment
This issue has not been assessed yet.