`sqlmesh plan --restate-model` requires model files to be present
Hi!
Since v0.119.0 sqlmesh run does not require any model definitions in the models/ to refresh model data.
While clearing some confusion I had about sqlmesh plan --restate-model's behavior, it was pointed out to me that it should only refresh data, but not update models' definitions (like a regular plan would).
So I expected that a restatement should also not require the definitions, if it only refreshes data. But when testing the behavior it does not seem to be the case.
repro
setup
$ uv venv && uv pip install sqlmesh && . .venv/bin/activate
$ sqlmesh --version
0.127.1
t.sh -- helper script
#!/usr/bin/env bash
function remove_definitions {
rm -rf models seeds tests audits macros logs .cache
}
remove_definitions
rm -rf config.yaml db.db
sqlmesh init duckdb
sqlmesh plan --auto-apply >/dev/null
remove_definitions
I believe a restatement shouldn't require model definitions in order to only refresh data, similar to run.
$ ./t.sh && sqlmesh plan -r sqlmesh_example.full_model -s '' -e '' --auto-apply
Error: `('/tmp/sqlmesh-tmp',)` doesn't seem to have any models... cd into the proper directory or specify the path(s) with -p.
Defining a dummy full_model makes it work:
$ mkdir models && echo 'MODEL (name sqlmesh_example.full_model); select 1 as foo' > models/full_model.sql
$ sqlmesh plan -r sqlmesh_example.full_model -s '' -e '' --auto-apply
No differences when compared to `prod`
Models needing backfill (missing dates):
└── sqlmesh_example.full_model: 2024-10-15 - 2024-10-15
[...]
The target environment has been updated successfully
And the original model definition is not replaced by the dummy that was introduced, as expected:
$ duckdb -c 'select * from sqlmesh_example.full_model' db.db
┌─────────┬────────────┐
│ item_id │ num_orders │
│ int32 │ int64 │
├─────────┼────────────┤
│ 2 │ 1 │
│ 1 │ 5 │
│ 3 │ 1 │
└─────────┴────────────┘
Am I misguided here?
Thanks in advance.
For completeness sake, to demonstrate that sqlmesh run behaves like this since v0.119:
$ uv pip install -U sqlmesh==0.118.0 && ./t.sh && sqlmesh run
[...]
Error: `('/tmp/sqlmesh-tmp',)` doesn't seem to have any models... cd into the proper directory or specify the path(s) with -p.
$ uv pip install -U sqlmesh==0.119.0 && ./t.sh && sqlmesh run
[...]
Run finished for environment 'prod'
This does look like a bug, @izeigerman can you verify?
Yes, restatements shouldn't require model files now that we purposefully ignore local changes when doing the restatement.
@izeigerman can you assign this to me. Thanks.