Skip to content

Commit 2294535

Browse files
committed
Add support for retrieving previous dev_mode from state
- Introduced `_get_prev_dev_mode_from_state` method to read the development mode from the raw state.json, ensuring compatibility with engine versions. - Updated `_configure` method to utilize the new method for determining previous dev_mode status. - Enhanced pipeline state migration to include dev_mode and initial working directory in the local state for engine version upgrades.
1 parent 81f0653 commit 2294535

File tree

2 files changed

+18
-2
lines changed

2 files changed

+18
-2
lines changed

dlt/pipeline/pipeline.py

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1235,6 +1235,19 @@ def _recreate_initial_state(self) -> None:
12351235
self._set_dataset_name(None)
12361236
self._save_state(state)
12371237

1238+
def _get_prev_dev_mode_from_state(self) -> bool:
1239+
"""Reads previous dev_mode from raw state.json only if engine supports it (>=2)."""
1240+
try:
1241+
raw = json_decode_state(self._pipeline_storage.load(Pipeline.STATE_FILE))
1242+
except FileNotFoundError:
1243+
return False
1244+
engine = int(raw.get("_state_engine_version", 1))
1245+
if engine >= 2:
1246+
return bool(raw.get("_local", {}).get("dev_mode", False))
1247+
else:
1248+
# legacy engine does not record dev flag
1249+
return False
1250+
12381251
def _configure(
12391252
self, import_schema_path: str, export_schema_path: str, must_attach_to_local_pipeline: bool
12401253
) -> None:
@@ -1258,7 +1271,7 @@ def _configure(
12581271
)
12591272

12601273
self.must_attach_to_local_pipeline = must_attach_to_local_pipeline
1261-
prev_dev_mode: bool = self.get_local_state_val("dev_mode") if has_state else False
1274+
prev_dev_mode: bool = self._get_prev_dev_mode_from_state() if has_state else False
12621275
should_recreate_pipeline: bool = prev_dev_mode and not self.dev_mode
12631276
self.set_local_state_val("dev_mode", self.dev_mode) # create schema storage
12641277
if has_state and not should_recreate_pipeline:

dlt/pipeline/state_sync.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,10 @@ def migrate_pipeline_state(
5757
if from_engine == to_engine:
5858
return cast(TPipelineState, state)
5959
if from_engine == 1 and to_engine > 1:
60-
state["_local"] = {}
60+
state["_local"] = {
61+
"dev_mode": state.get("dev_mode", False),
62+
"initial_cwd": os.path.abspath(dlt.current.run_context().local_dir),
63+
}
6164
from_engine = 2
6265
if from_engine == 2 and to_engine > 2:
6366
# you may want to recompute hash

0 commit comments

Comments
 (0)