apache/superset · error · DatabaseUploadFailed

error_msg

Error message

error_msg

What it means

DatabaseUploadFailed raised by CSVReader._cast_single_column when converting an uploaded CSV column to the user-specified type fails. The message is built by _create_error_message and lists the offending values with their source line numbers (e.g. "Cannot convert column 'id' to int64. Found 2 error(s): Line 5: value 'abc'"); if detail-building itself fails, a fallback message 'Cannot convert column '<c>' to <dtype>. <original error>' is used. It wraps ValueError/TypeError from pd.to_numeric(errors='raise') or DataFrame.astype.

Source

Thrown at superset/commands/database/uploaders/csv_reader.py:307

                df[column] = df[column].astype(dtype)
            else:
                df[column] = df[column].astype(dtype)
        except (ValueError, TypeError) as ex:
            try:
                if dtype in numeric_types:
                    invalid_mask = CSVReader._find_invalid_values_numeric(df, column)
                else:
                    invalid_mask = CSVReader._find_invalid_values_non_numeric(
                        df, column, dtype
                    )

                error_msg = CSVReader._create_error_message(
                    df, column, dtype, invalid_mask, kwargs, ex
                )
            except Exception:
                error_msg = f"Cannot convert column '{column}' to {dtype}. {str(ex)}"

            raise DatabaseUploadFailed(message=error_msg) from ex

    @staticmethod
    def _cast_column_types(
        df: pd.DataFrame, types: dict[str, str], kwargs: dict[str, Any]
    ) -> pd.DataFrame:
        """
        Cast DataFrame columns to specified types with detailed
        error reporting.

        :param df: DataFrame to cast
        :param types: Dictionary mapping column names to target types
        :param kwargs: Original read_csv kwargs for line number calculation
        :return: DataFrame with casted columns
        :raises DatabaseUploadFailed: If type conversion fails with detailed error info
        """
        for column, dtype in types.items():
            if column not in df.columns:
                continue

View on GitHub (pinned to f4587218dd)

Solutions

  1. Read the detailed message: it names the column, target dtype, and exact lines/values — fix those rows in the CSV or choose the right type
  2. For values like '1,000' or '$5.00', clean them in the source or map the column to string/float64 instead of int64
  3. For mostly-numeric columns with occasional blanks, use float64 (which tolerates NaN) rather than int64
  4. Re-run the upload; the same validation runs again and will confirm the fix

Example fix

# before: column declared int64 but row 5 contains 'abc'
id
1
abc   <- Line 5
# after: correct the data
id
1
7
# or choose dtype float64/string in the column-type picker
Defensive patterns

Strategy: validation

Validate before calling

import pandas as pd

def cast_preview(csv_path: str, types: dict[str, str]) -> list[str]:
    df = pd.read_csv(csv_path, nrows=1000)
    bad = []
    for col, dtype in types.items():
        try:
            pd.to_numeric(df[col]) if dtype in {"int64", "float64", "int32", "float32"} else df[col].astype(dtype)
        except (ValueError, TypeError):
            bad.append(col)
    return bad  # fix columns in this list before upload

Try / catch

except DatabaseUploadFailed as ex:
    # message already lists offending values + line numbers; feed back to user verbatim
    show_inline_errors(str(ex))

Prevention

When it happens

Trigger: Uploading a CSV and declaring a column type (the types mapping) that the data violates: 'abc' in an int64 column, '1.5' in int64, empty strings in numeric columns, or strings longer than the target dtype permits; line numbers are derived from the original read_csv kwargs (header/skiprows) so they map to the physical CSV rows.

Common situations: Excel exports with thousands separators ('1,000') or currency symbols ('$5.00'); European decimal commas ('3,14') parsed as strings; blank cells in NOT NULL integer columns; users picking int64 for columns that legitimately contain floats.

Related errors


AI-assisted analysis of apache/superset@f4587218dd (2026-08-14). Data as JSON: /api/errors/ce69343c3e096ff0. Report an issue: GitHub.