{"record":{"id":"132f43d4bdbfa0db","repo":"SeaQL/sea-orm","slug":"cannot-apply-alias-for-asenum-with-asterisk-132f43","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":"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/src/query/combine.rs#L47-L83","documentation":"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.","triggerScenarios":"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.","commonSituations":"Hand-built select lists that combine .as_enum(...) casts with select_all-style wildcards; copy-pasted select expressions never narrowed to a concrete column.","solutions":["Name the concrete column inside the AsEnum expression instead of an asterisk","Apply the enum cast only to a specific column: Expr::col(col).as_enum(...)","Build the aliased query without AsEnum on wildcard selects"],"exampleFix":"// before\nExpr::asterisk().as_enum(MyEnum)\n// after\nExpr::col((entity, my_col)).as_enum(MyEnum)","handlingStrategy":"validation","validationCode":"fn as_enum_inner_is_column(expr: &SimpleExpr) -> bool {\n    matches!(expr, SimpleExpr::AsEnum(_, inner)\n        if matches!(inner.as_ref(), SimpleExpr::Column(c) if c.column().is_some()))\n}","typeGuard":"fn enum_wrapped_column(expr: &SimpleExpr) -> bool {\n    match expr {\n        SimpleExpr::AsEnum(_, inner) => matches!(inner.as_ref(), SimpleExpr::Column(c) if c.column().is_some()),\n        _ => false,\n    }\n}","tryCatchPattern":"// panics are not catchable; guard before building\ndebug_assert!(as_enum_inner_is_column(&expr), \"AsEnum must wrap a concrete column\");","preventionTips":["Wrap only named columns in .as_enum(...), never asterisk","Review generated select exprs for wildcard casts","Keep enum-cast helpers constrained to typed columns"],"tags":["panic","query-builder","alias","enum"],"backgroundTag":"unsupported-operation","analyzedSha":"e29bcd1b417c41a553b386fe94511d7c64a1c8ec","analyzedAt":"2026-09-10T11:31:52.468Z","contentChangedAt":"2026-09-10T11:31:52.468Z","schemaVersion":2},"datasetVersion":"2026-09-14T11:17:12.474Z"}