You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
"When targeting the production environment either the backfill should not be skipped or the lack of data gaps should be enforced (--no-gaps flag)."
1521
+
# note: we deliberately don't mention the --no-gaps flag in case the plan came from the sqlmesh_dbt command
1522
+
# todo: perhaps we could have better error messages if we check sys.argv[0] for which cli is running?
1523
+
self.console.log_warning(
1524
+
"Skipping the backfill stage for production can lead to unexpected results, such as tables being empty or incremental data with non-contiguous time ranges being made available.\n"
1525
+
"If you are doing this deliberately to create an empty version of a table to test a change, please consider using Virtual Data Environments instead."
Copy file name to clipboardExpand all lines: sqlmesh_dbt/operations.py
+11-8Lines changed: 11 additions & 8 deletions
Original file line number
Diff line number
Diff line change
@@ -127,15 +127,12 @@ def _plan_options(
127
127
)
128
128
129
129
ifempty:
130
-
# dbt --empty adds LIMIT 0 to the queries, resulting in empty tables
131
-
# this lines up with --skip-backfill in SQLMesh
130
+
# `dbt --empty` adds LIMIT 0 to the queries, resulting in empty tables. In addition, it happily clobbers existing tables regardless of if they are populated.
131
+
# This *partially* lines up with --skip-backfill in SQLMesh, which indicates to not populate tables if they happened to be created/updated as part of this plan.
132
+
# However, if a table already exists and has data in it, there is no change so SQLMesh will not recreate the table and thus it will not be cleared.
133
+
# So in order to fully replicate dbt's --empty, we also need --full-refresh semantics in order to replace existing tables
132
134
options["skip_backfill"] =True
133
-
134
-
ifis_prod:
135
-
# to prevent the following error:
136
-
# > ConfigError: When targeting the production environment either the backfill should not be skipped or
137
-
# > the lack of data gaps should be enforced (--no-gaps flag).
138
-
options["no_gaps"] =True
135
+
full_refresh=True
139
136
140
137
iffull_refresh:
141
138
# TODO: handling this requires some updates in the engine to enable restatements+changes in the same plan without affecting prod
@@ -186,6 +183,12 @@ def create(
186
183
fromsqlmesh_dbt.consoleimportDbtCliConsole
187
184
fromsqlmesh.utils.errorsimportSQLMeshError
188
185
186
+
# clear any existing handlers set up by click/rich as defaults so that once SQLMesh logging config is applied,
187
+
# we dont get duplicate messages logged from things like console.log_warning()
"Error: When targeting the production environment either the backfill should not be skipped or the lack of data gaps should be enforced (--no-gaps flag)."
265
-
inresult.output
264
+
"Skipping the backfill stage for production can lead to unexpected results"inresult.output
266
265
)
267
266
268
267
# plan executes virtual update without executing model batches
0 commit comments