@@ -1047,3 +1047,37 @@ def test_dsl_no_jit_backend_not_in_schema():
10471047 schema = t ._schema_dict_with_computed ()
10481048 mat = {m ["name" ]: m for m in schema ["materialized_columns" ]}
10491049 assert "jit_backend" not in mat ["total" ]
1050+
1051+
1052+ def test_add_computed_column_empty_expression_raises (monkeypatch ):
1053+ """add_computed_column raises ValueError when the LazyExpr serializes to empty string."""
1054+ t = _make_invoice_table ()
1055+
1056+ original_normalize = t ._normalize_expression_transformer .__func__
1057+
1058+ def patched (self , expr ):
1059+ lazy , col_deps = original_normalize (self , expr )
1060+ monkeypatch .setattr (lazy , "expression" , "" )
1061+ return lazy , col_deps
1062+
1063+ monkeypatch .setattr (type (t ), "_normalize_expression_transformer" , patched )
1064+
1065+ with pytest .raises (ValueError , match = "empty string" ):
1066+ t .add_computed_column ("total" , lambda cols : cols ["price" ] * cols ["qty" ])
1067+
1068+
1069+ def test_add_computed_column_malformed_expression_raises (monkeypatch ):
1070+ """add_computed_column raises ValueError when the expression string cannot be re-parsed."""
1071+ t = _make_invoice_table ()
1072+
1073+ original_normalize = t ._normalize_expression_transformer .__func__
1074+
1075+ def patched (self , expr ):
1076+ lazy , col_deps = original_normalize (self , expr )
1077+ monkeypatch .setattr (lazy , "expression" , "this is not valid @@@ numexpr" )
1078+ return lazy , col_deps
1079+
1080+ monkeypatch .setattr (type (t ), "_normalize_expression_transformer" , patched )
1081+
1082+ with pytest .raises (ValueError , match = "cannot be safely persisted" ):
1083+ t .add_computed_column ("total" , lambda cols : cols ["price" ] * cols ["qty" ])
0 commit comments