Open ernstki opened 4 months ago
This happens somewhat-consistently on a second, nearly identical server. But it is an intermittent problem that sometimes appears to go away for a while when I reorder some columns in the query.
So, basically, no way to predict where the fault is without knowing where to turn up the debug level or watch the data flow. Are there any facilities for that, apart from just step-debugging in a local instance?
Does "empty CSV file except for the header row" sound like a common failure mode?
interesting -- let me try to replicate locally.
Out of curiosity, what is the barrier to going to 4.x? It should function identically -- but adds some nice stuff like autocompletion, etc. in the code editor (and, optionally, an AI-assistant thingy). Have you forked it and made a bunch of changes?
Sorry, I read the initial message more closely and see why you have not upgraded. If you have changes you think are valuable, I'd love to know what they are and could incorporate them potentially.
Thanks, and no great urgency on this one. Mostly just wanted to have the workaround spelled out so I could point at it from local documentation.
Out of curiosity, what is the barrier to going to 4.x? It should function identically -- but adds some nice stuff like autocompletion, etc. in the code editor (and, optionally, an AI-assistant thingy). Have you forked it and made a bunch of changes?
Mostly just the squished input fields for parameterized queries (screenshot above), and the fact that we've already extended the templates for 3.x to link back to the parent Django application in ways that everyone's used to at this point.
Also, to be honest, because I can actually work on 3.x, but I'm not quite ready for Vite, Vue, and all the JavaScript tooling necessary to tinker with 4.x / 5.x. Some day!
Since I've at least identified this as an intermittent fault, maybe I should try to trigger the behavior again with 4.x and the 5.x beta. Just in case it's something that's carried forward into the still-supported releases. I'll report back if I get a chance to do that.
Re: 4.x -- that makes sense. Although I spent a ton of time making sure it is super easy to work on (though it pains me too that it is now more intimidating). There is a start.sh script that sets it all up -- and the dev experience is actually quite a bit nicer thanks to live reloading. In fact, if you pull it down and run it, when you view the app -- it will detect that you don't have Vite running and give you instructions right in the browser to do it. You don't even have to read the docs! But yeah - I totally get it.
The JS in the templates ultimately just got way too complex and was hard to deal with.
Ok -- onto the issue:
Looking at the code, I don't see anything obvious that would end up returning just headers. It does seem weird...like you would expect the query to fail entirely; not return headers only.
I would recommend adding some additional logging in the explorer.models.QueryResult.__init__()
method. It looks something like:
def __init__(self, sql, connection):
self.sql = sql
self.connection = connection
cursor, duration = self.execute_query()
self._description = cursor.description or []
self._data = [list(r) for r in cursor.fetchall()]
self.duration = duration
cursor.close()
self._headers = self._get_headers()
self._summary = {}
You could add some code in there to capture cases where self._description is populated (the headers) but then self._data ends up empty. Perhaps the cursor is being somehow reused and I should refactor this to a with
block or something?
Lastly, even though you specifically did not ask for SQL advice -- I can't help myself. Refactoring that query to use a common table expression (which is super easy) will make it much easier to read :) And the AI assistant will happily do it for you if you ask!
Lastly here are some suggestions (towards the end) on how to add some additional monitoring to that function:
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 (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.
Workaround
Open the most recent query from the query logs in Playground, export the CSV from there:
explorer/logs
, relative to your Django app)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 aSELECT
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.