leaf icon indicating copy to clipboard operation
leaf copied to clipboard

Insufficient debug info in logs when "Error Loading Dataset"

Open jnothman opened this issue 3 years ago • 7 comments

I am trying to use "Add More Data" having defined an additional dataset per Adding New Datasets.

Despite the request (http://localhost:3000/api/cohort/b9b5433e-f36b-1410-8d86-0052d9c6700c/dataset?datasetid=a4b5433e-f36b-1410-8d86-0052d9c6700c&shape=-1) returning HTTP 500, I only get Information-level log entries. The most informative is "MessageTemplate": "Dataset compiler validation context. Context:{@Context}". It includes "State": "Ok".

The subsequent log event is "Executing HttpStatusCodeResult, setting HTTP status code {StatusCode}".

Should there be another log event in between? There's no current log event giving me the complete SQL selecting this dataset's values only for the selected cohort, nor can I see a log event with the traceback of an error.

jnothman avatar Oct 27 '21 02:10 jnothman

Hmm... maybe this is more specific to our case, as making other errors in the dataset definition results in a Failed to fetch dataset. log entry. So there seems to be a case that is silently resulting in an HTTP 500 before Compiled dataset execution context

jnothman avatar Oct 27 '21 07:10 jnothman

My specific case may be related to the use of a WITH clause preceding SELECT...

jnothman avatar Oct 27 '21 22:10 jnothman

Hi @jnothman,

Ah the WITH may be the issue, which would result in an invalid SQL statement. Leaf wraps your SQL statement in a CTE already, where the dataset parameter in the below function is the SQL statement you compose: image

So the CTE-within-a-CTE is invalid. Leaf expects your SQL to be of the traditional SELECT ... FROM ... WHERE variety.

An alternative would be to first make a View and include the CTE there, then call the View.

ndobb avatar Oct 28 '21 19:10 ndobb

Can I nest a SELECT clause within FROM? that might also work.

jnothman avatar Oct 28 '21 23:10 jnothman

It does!

Still, the lack of full SQL statement in the logs made it much harder to dig into.

jnothman avatar Oct 28 '21 23:10 jnothman

@jnothman, can you check your logs for an entry with a message like "Compiled dataset execution context:"?

You should be able to find the SQL statement under Properties.Context.CompiledQuery.

ndobb avatar Oct 29 '21 00:10 ndobb

No I'm not seeing that log. I assume it's breaking on the previous line in compiler.BuildDatasetSql(validationContext.Context); but I'm surprised I see nothing like a traceback, just a log for setting HTTP 500.

jnothman avatar Oct 31 '21 22:10 jnothman