{"record":{"id":"ca3b3ab5f36979b9","repo":"SeaQL/sea-orm","slug":"cannot-apply-alias-for-asenum-with-asterisk","errorCode":null,"errorMessage":"cannot apply alias for AsEnum with asterisk","messagePattern":"cannot apply alias for AsEnum with asterisk","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"error","filePath":"sea-orm-sync/src/query/combine.rs","lineNumber":65,"sourceCode":"        self.query().exprs_mut_for_each(|sel| {\n            match &sel.alias {\n                Some(alias) => {\n                    let alias = format!(\"{}{}\", pre, alias.to_string().as_str());\n                    sel.alias = Some(alias.into_iden());\n                }\n                None => {\n                    let col = match &sel.expr {\n                        SimpleExpr::Column(col_ref) => match col_ref.column() {\n                            Some(col) => col,\n                            None => {\n                                panic!(\"cannot apply alias for Column with asterisk\");\n                            }\n                        },\n                        SimpleExpr::AsEnum(_, simple_expr) => match simple_expr.as_ref() {\n                            SimpleExpr::Column(col_ref) => match col_ref.column() {\n                                Some(col) => col,\n                                None => {\n                                    panic!(\"cannot apply alias for AsEnum with asterisk\")\n                                }\n                            },\n                            _ => {\n                                panic!(\"cannot apply alias for AsEnum with expr other than Column\")\n                            }\n                        },\n                        _ => panic!(\"cannot apply alias for expr other than Column or AsEnum\"),\n                    };\n                    let alias = format!(\"{}{}\", pre, col.to_string().as_str());\n                    sel.alias = Some(alias.into_iden());\n                }\n            };\n        });\n        self\n    }\n\n    /// Selects extra Entity and returns it together with the Entity from `Self`\n    pub fn select_also<F>(mut self, _: F) -> SelectTwo<E, F>","sourceCodeStart":47,"sourceCodeEnd":83,"githubUrl":"https://github.com/SeaQL/sea-orm/blob/e29bcd1b417c41a553b386fe94511d7c64a1c8ec/sea-orm-sync/src/query/combine.rs#L47-L83","documentation":"In `apply_alias`, when a selected expression is wrapped as `SimpleExpr::AsEnum`, the code unwraps it to an inner `SimpleExpr::Column` to derive the column name for the prefixed alias. If the inner column reference is an asterisk (wildcard, `col_ref.column()` returns None), no column name exists to build an alias from, so the library panics rather than emit a corrupt `SELECT * AS alias_x` clause. This is a deliberate internal invariant violation guard.","triggerScenarios":"Calling `select_also`, `select_also_fake`, `select_with`, `select_two_required`, or `left_join_linked` on a SelectTwo/SelectThree whose selected column list contains a `SimpleExpr::AsEnum` wrapping a wildcard/asterisk column expression (e.g. a `DeriveValueType` enum column selected via `Expr::col(...).into_column()` with Asterisk, or selecting all columns where one is an enum wrapper that got AsEnum-wrapped as asterisk).","commonSituations":"Selecting a whole table's columns (`.*`) in a combined select while at least one column is a SeaORM enum (DeriveValueType/DeriveActiveEnum) column, so the aliasing pass encounters `AsEnum(Asterisk)`. Typically appears when refactoring a join query to `select_also`/`select_with` without listing explicit columns.","solutions":["Select the enum column explicitly instead of using the asterisk/wildcard: use `.column(entity::COLUMN.my_enum_col)` so the AsEnum wraps a named Column.","Remove the wildcard select from the query; enumerate the needed columns so each AsEnum expression resolves to a concrete column.","If the wildcard comes from a helper building the select, change it to skip AsEnum-wrapped expressions or expand them per-column before calling select_also/select_with.","If you believe wildcard + enum selection should be supported, file an issue; as a workaround apply the enum conversion after fetching the raw column instead of via AsEnum in the select."],"exampleFix":"// before\nlet rows = cake::Entity::find()\n    .join(JoinType::LeftJoin, fruit::Relation::Cake.def())\n    .select_also(fruit::Entity) // aliasing pass sees AsEnum over asterisk\n    .into_model::<CakeFruit>()\n    .one(db).await?;\n\n// after\nlet rows = cake::Entity::find()\n    .column_as(cake::COLUMN.id, \"cake_id\")\n    .column(cake::COLUMN.name) // explicit enum (AsEnum) columns, not wildcard\n    .join(JoinType::LeftJoin, fruit::Relation::Cake.def())\n    .select_also(fruit::Entity)\n    .into_model::<CakeFruit>()\n    .one(db).await?;","handlingStrategy":"validation","validationCode":"// Ensure every AsEnum-wrapped select item targets a named column before combined select\nfn assert_no_wildcard_enum_select<E: EntityTrait>(sel: &Select<E>) -> bool { sel.query().distinct().is_ok() } // build selects explicitly; prefer:\n// prefer: only pass enums via .column(entity::COLUMN.col) — never .* in select_also/select_with\ntrue","typeGuard":"fn is_named_column_select(expr: &SimpleExpr) -> bool {\n    match expr {\n        SimpleExpr::Column(c) => c.column().is_some(),\n        SimpleExpr::AsEnum(_, inner) => matches!(inner.as_ref(), SimpleExpr::Column(c) if c.column().is_some()),\n        _ => false,\n    }\n}","tryCatchPattern":null,"preventionTips":["Never select table wildcards (`.column(Expr::col(...).asterisk())`) in queries passed to select_also/select_with/left_join_linked.","List enum columns explicitly with `entity::COLUMN.name` so AsEnum always wraps a named Column.","Add a debug-mode unit test that builds each combined query once; the panic fires at query build time, so test-builds catch it early."],"tags":["panic","seaorm","query-builder","select-alias","enum-column"],"backgroundTag":"internal-invariant-violation","analyzedSha":"e29bcd1b417c41a553b386fe94511d7c64a1c8ec","analyzedAt":"2026-09-10T11:31:52.468Z","contentChangedAt":"2026-09-10T11:31:52.468Z","schemaVersion":2},"datasetVersion":"2026-09-14T05:17:10.506Z"}