@@ -9246,6 +9246,7 @@ def test_python_env_references_are_unequal_but_point_to_same_definition(tmp_path
92469246
92479247 db_path = str (tmp_path / "db.db" )
92489248 db_connection = DuckDBConnectionConfig (database = db_path )
9249+
92499250 config = Config (
92509251 gateways = {"duckdb" : GatewayConfig (connection = db_connection )},
92519252 model_defaults = ModelDefaultsConfig (dialect = "duckdb" ),
@@ -9361,3 +9362,92 @@ def f():
93619362
93629363 with pytest .raises (SQLMeshError , match = r"duplicate definitions found" ):
93639364 Context (paths = tmp_path , config = config )
9365+
9366+
9367+ def test_semicolon_is_not_included_in_model_state (tmp_path , assert_exp_eq ):
9368+ init_example_project (tmp_path , dialect = "duckdb" , template = ProjectTemplate .EMPTY )
9369+
9370+ db_path = str (tmp_path / "db.db" )
9371+ db_connection = DuckDBConnectionConfig (database = str (tmp_path / "db.db" ))
9372+
9373+ model_file = tmp_path / "models" / "model_with_semicolon.sql"
9374+ model_file .write_text (
9375+ """
9376+ MODEL (
9377+ name sqlmesh_example.incremental_model_with_semicolon,
9378+ kind INCREMENTAL_BY_TIME_RANGE (
9379+ time_column event_date
9380+ ),
9381+ start '2020-01-01',
9382+ cron '@daily',
9383+ grain (id, event_date)
9384+ );
9385+
9386+ SELECT
9387+ 1 AS id,
9388+ 1 AS item_id,
9389+ CAST('2020-01-01' AS DATE) AS event_date
9390+ ;
9391+
9392+ --Just a comment
9393+ """
9394+ )
9395+
9396+ ctx = Context (paths = tmp_path , config = config )
9397+ model = ctx .get_model ("sqlmesh_example.incremental_model_with_semicolon" )
9398+
9399+ assert not model .pre_statements
9400+ assert not model .post_statements
9401+
9402+ assert_exp_eq (
9403+ model .render_query (),
9404+ 'SELECT 1 AS "id", 1 AS "item_id", CAST(\' 2020-01-01\' AS DATE) AS "event_date"' ,
9405+ )
9406+ ctx .format ()
9407+
9408+ assert (
9409+ model_file .read_text ()
9410+ == """MODEL (
9411+ name sqlmesh_example.incremental_model_with_semicolon,
9412+ kind INCREMENTAL_BY_TIME_RANGE (
9413+ time_column event_date
9414+ ),
9415+ start '2020-01-01',
9416+ cron '@daily',
9417+ grain (id, event_date)
9418+ );
9419+
9420+ SELECT
9421+ 1 AS id,
9422+ 1 AS item_id,
9423+ '2020-01-01'::DATE AS event_date;
9424+
9425+ /* Just a comment */"""
9426+ )
9427+
9428+ ctx .plan (no_prompts = True , auto_apply = True )
9429+
9430+ model_file = tmp_path / "models" / "model_with_semicolon.sql"
9431+ model_file .write_text (
9432+ """
9433+ MODEL (
9434+ name sqlmesh_example.incremental_model_with_semicolon,
9435+ kind INCREMENTAL_BY_TIME_RANGE (
9436+ time_column event_date
9437+ ),
9438+ start '2020-01-01',
9439+ cron '@daily',
9440+ grain (id, event_date)
9441+ );
9442+
9443+ SELECT
9444+ 1 AS id,
9445+ 1 AS item_id,
9446+ CAST('2020-01-01' AS DATE) AS event_date
9447+ """
9448+ )
9449+
9450+ ctx .load ()
9451+ plan = ctx .plan (no_prompts = True , auto_apply = True )
9452+
9453+ assert not plan .context_diff .modified_snapshots
0 commit comments