Skip to content

Commit

Permalink
* Fixing a race condition in the draft phase (#131)
Browse files Browse the repository at this point in the history
  • Loading branch information
sp-tkerlavage authored Mar 11, 2024
1 parent 764d1dc commit 984121a
Showing 1 changed file with 12 additions and 6 deletions.
18 changes: 12 additions & 6 deletions src/dbt_osmosis/core/osmosis.py
Original file line number Diff line number Diff line change
Expand Up @@ -598,12 +598,6 @@ def _draft(self, schema_file: SchemaFileLocation, unique_id: str, blueprint: dic
schema_file.current, []
).append(node)
break
for k in blueprint:
# Remove if sources or models are empty
if blueprint[k].output.get("sources", None) == []:
del blueprint[k].output["sources"]
if blueprint[k].output.get("models", None) == []:
del blueprint[k].output["models"]

except Exception as e:
with self.mutex:
Expand Down Expand Up @@ -637,6 +631,16 @@ def draft_project_structure_update_plan(self) -> Dict[Path, SchemaFileMigration]
futs.append(self.tpe.submit(self._draft, schema_file, unique_id, blueprint))
wait(futs)
return blueprint

def cleanup_blueprint(self, blueprint: dict) -> None:
with self.mutex:
for k in list(blueprint.keys()):
# Remove if sources or models are empty
if blueprint[k].output.get("sources", None) == []:
del blueprint[k].output["sources"]
if blueprint[k].output.get("models", None) == []:
del blueprint[k].output["models"]
return blueprint

def commit_project_restructure_to_disk(
self, blueprint: Optional[Dict[Path, SchemaFileMigration]] = None
Expand All @@ -657,6 +661,8 @@ def commit_project_restructure_to_disk(
# Build blueprint if not user supplied
if not blueprint:
blueprint = self.draft_project_structure_update_plan()

blueprint = self.cleanup_blueprint(blueprint)

# Verify we have actions in the plan
if not blueprint:
Expand Down

0 comments on commit 984121a

Please sign in to comment.