SeaQL/sea-orm · error

cannot apply alias for AsEnum with asterisk

Error message

cannot apply alias for AsEnum with asterisk

What it means

When a selected expression is wrapped in SimpleExpr::AsEnum (cast of a column to an enum type), apply_alias inspects the inner expression expecting a concrete Column. If the inner column is an asterisk/wildcard, no column name exists to build the alias from and the library panics with this message.

Source

Thrown at src/query/combine.rs:65

        self.query().exprs_mut_for_each(|sel| {
            match &sel.alias {
                Some(alias) => {
                    let alias = format!("{}{}", pre, alias.to_string().as_str());
                    sel.alias = Some(alias.into_iden());
                }
                None => {
                    let col = match &sel.expr {
                        SimpleExpr::Column(col_ref) => match col_ref.column() {
                            Some(col) => col,
                            None => {
                                panic!("cannot apply alias for Column with asterisk");
                            }
                        },
                        SimpleExpr::AsEnum(_, simple_expr) => match simple_expr.as_ref() {
                            SimpleExpr::Column(col_ref) => match col_ref.column() {
                                Some(col) => col,
                                None => {
                                    panic!("cannot apply alias for AsEnum with asterisk")
                                }
                            },
                            _ => {
                                panic!("cannot apply alias for AsEnum with expr other than Column")
                            }
                        },
                        _ => panic!("cannot apply alias for expr other than Column or AsEnum"),
                    };
                    let alias = format!("{}{}", pre, col.to_string().as_str());
                    sel.alias = Some(alias.into_iden());
                }
            };
        });
        self
    }

    /// Selects extra Entity and returns it together with the Entity from `Self`
    pub fn select_also<F>(mut self, _: F) -> SelectTwo<E, F>

View on GitHub (pinned to e29bcd1b41)

Solutions

  1. Name the concrete column inside the AsEnum expression instead of an asterisk
  2. Apply the enum cast only to a specific column: Expr::col(col).as_enum(...)
  3. Build the aliased query without AsEnum on wildcard selects

Example fix

// before
Expr::asterisk().as_enum(MyEnum)
// after
Expr::col((entity, my_col)).as_enum(MyEnum)
Defensive patterns

Strategy: validation

Validate before calling

fn as_enum_inner_is_column(expr: &SimpleExpr) -> bool {
    matches!(expr, SimpleExpr::AsEnum(_, inner)
        if matches!(inner.as_ref(), SimpleExpr::Column(c) if c.column().is_some()))
}

Type guard

fn enum_wrapped_column(expr: &SimpleExpr) -> bool {
    match expr {
        SimpleExpr::AsEnum(_, inner) => matches!(inner.as_ref(), SimpleExpr::Column(c) if c.column().is_some()),
        _ => false,
    }
}

Try / catch

// panics are not catchable; guard before building
debug_assert!(as_enum_inner_is_column(&expr), "AsEnum must wrap a concrete column");

Prevention

When it happens

Trigger: Using select_also/select_with/select_two_required/left_join_linked where a select expression is AsEnum wrapping an asterisk Column — e.g. casting a wildcard select to an enum instead of naming a real column.

Common situations: Hand-built select lists that combine .as_enum(...) casts with select_all-style wildcards; copy-pasted select expressions never narrowed to a concrete column.

Understand the failure class

Background: UnsupportedOperationException and "is not supported" errors: when a library deliberately refuses a call — this error's family across 30 libraries.

Related errors


AI-assisted analysis of SeaQL/sea-orm@e29bcd1b41 (2026-09-10). Data as JSON: /api/errors/132f43d4bdbfa0db. Report an issue: GitHub.