Bug description

I’m encountering an issue with the API (/api/v1/chart/data) when fetching chart data. The error message states: 'Datetime column not provided as part of the table configuration and is required for this chart type.' Although the chart renders correctly in the UI, the API call fails. As a workaround, opening and saving the chart without making any changes resolves the issue. Has a fix been implemented for this? Same issue was reported earlier - https://apache-superset.slack.com/archives/C015WAZL0KH/p1667844640596479 Chart details - Temporal X-Axis - day column (timestamp) Time Grain - Week

How to reproduce the bug

Query context payload difference between initial version rendered and changes occurred after saving the chart without changes. Apache Superset APi - /api/v1/chart/data - failing for missing Datetime column not provided for certain charts only Apache Superset APi - /api/v1/chart/data - failing for missing Datetime column not provided for certain charts only

Screenshots/recordings

No response

Superset version

master / latest-dev

Python version

3.10

Node version

16

Browser

Chrome

Additional context

No response

Checklist

  • [X] I have searched Superset docs and Slack and didn't find a solution to my problem.
  • [ ] I have searched the GitHub issue tracker and didn't find a similar bug report.
  • [X] I have checked Superset's logs for errors and if I found a relevant Python stacktrace, I included it here as text in the "additional context" section.

Comment From: dosubot[bot]

Hey @dineshvk2! I'm here to help you with any bugs, questions, or contributions you have regarding the API issue. Let's work together to find a solution.

A similar issue has been reported and addressed. The error occurs when the granularity variable is not provided and the is_timeseries variable is True. This triggers the 'Datetime column not provided' error in the API [1].

A fix has been implemented to address this issue. The specific change involves ensuring that the temporal column is added first to the columns array if it meets certain conditions. Here is the relevant code snippet:

const temporalColumnsLookup = formData?.temporal_columns_lookup;
// Filter out the column if needed and prepare the temporal column object

columns = columns.filter(col => {
  const shouldBeAdded =
    isPhysicalColumn(col) &&
    time_grain_sqla &&
    temporalColumnsLookup?.[col];
  if (shouldBeAdded && !temporalColumnAdded) {
    temporalColumn = {
      timeGrain: time_grain_sqla,
      columnType: 'BASE_AXIS',
      sqlExpression: col,
      label: col,
      expressionType: 'SQL',
    } as AdhocColumn;
    temporalColumnAdded = true;
    return false; // Do not include this in the output; it's added separately
  }
  return true;
});

// So we ensure the temporal column is added first
if (temporalColumn) {
  columns = [temporalColumn, ...columns];
}

This code ensures that the temporal column is correctly added, thus resolving the issue with the missing Datetime column [2].

Additionally, saving the chart without making any changes updates the metadata state, ensuring that the metadata used for rendering in the UI and the metadata sent in the API call are synchronized. This resolves any discrepancies and prevents the error from occurring [3].

For best practices, always specify the granularity parameter for timeseries charts and ensure that the Datetime column is correctly configured in the table schema [1][4].

To continue talking to Dosu, mention @dosu.

Comment From: rusackas

I'm not sure what to make of this one, and I'm guessing others aren't either, thus it's at at-risk of being closed as stale/not-planned. Are you still facing this issue in 4.1.2 or newer? There may have been some API changes in that time.

You also mention this is an API question... if you can give a failing payload/CURL with example dashboards/charts/data, that would help us reproduce it at least.

Comment From: rusackas

Since we haven't heard back with any context in newer versions, or any repro steps, I'll close this as not-planned. Happy to revisit/reopen with more context.