sqlmesh icon indicating copy to clipboard operation
sqlmesh copied to clipboard

Plan fails with option --select-model after making a change

Open cams-data opened this issue 6 months ago • 3 comments

I'm running the following command: uv run sqlmesh plan --select-model "ch_bronze_nz_stats.areas__regional_council_clipped" -vv after making changes to ch_bronze_nz_stats.areas__regional_council_clipped

And am getting: Updating virtual layer ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━╸━━━ 92.3% • 24/26 • 0:00:01 Error: Execution failed for node SnapshotId<"ch_silver_geography"."geographic_area_shapes": 1549095793>

"ch_silver_geography"."geographic_area_shapes" is downstream of "ch_bronze_nz_stats.areas__regional_council_clipped"

When I inspect the logs I can see: clickhouse_connect.driver.exceptions.DatabaseError: Received ClickHouse exception, code: 60, server response: Code: 60. DB::Exception: Unknown table expression identifier 'sqlmesh__ch_silver.ch_silver_geography__geographic_area_shapes__3267957768' in scope SELECT * FROM sqlmesh__ch_silver.ch_silver_geography__geographic_area_shapes__3267957768. (UNKNOWN_TABLE) (for url [redacted]) I have checked the database and can see that across all replicas sqlmesh__ch_silver.ch_silver_geography__geographic_area_shapes__3267957768 does not exist. So it seems the fingerprint for the downstream model has changed, but no physical table was created for it to match? I can see the old table in there sqlmesh__ch_silver.ch_silver_geography__geographic_area_shapes__3737929073

If I run the update without --select-model it works, but I had thought even with that option, downstream models that are indirectly affected, would update?

cams-data avatar May 29 '26 05:05 cams-data

@cams-data are you still facing this issue?

  • Did it backfill any data into that model prior to the virtual updates? If so, try --skip-backfill flag and see if you can apply the virtual updates by themselves
  • Maybe add a + to the end of your model select?

mday-io avatar Jun 12 '26 14:06 mday-io

@mday-io Thanks for the suggestions. I made a code change to the model ch_bronze_nz_stats.areas__regional_council_clipped and then ran the above plan command. I am under the impression that SQLMesh should handle everything from there. I do not understand why I would be expected to add --skip-backfill when I need the physical data updated? I could try adding the + symbol, but again, from what the docs seem to suggest, all of the models that are downstream of the selected model should update correctly regardless?

This issue still persists by the way.

cams-data avatar Jun 13 '26 00:06 cams-data

I've experienced circumstances where skipping the backfill and only applying virtual updates corrected a snapshotting and pointer issue. My thought was you could skip backfill, hopefully successfully complete the virtual update, and then run the backfill.

Yeah, I would try to explicitly use the +.

you could also run plan --explain and share the results here. You could also try create a new dev environment?

mday-io avatar Jun 15 '26 15:06 mday-io