Skip to content

Commit

Permalink
Copy blueprints during conversion in SingleDB mode, avoid issues with…
Browse files Browse the repository at this point in the history
… updating objects by reference
  • Loading branch information
littleK0i committed Oct 11, 2024
1 parent f3890b8 commit ed9f3ff
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 7 deletions.
8 changes: 5 additions & 3 deletions snowddl/app/singledb.py
Original file line number Diff line number Diff line change
Expand Up @@ -250,10 +250,12 @@ def convert_config(self, original_config: SnowDDLConfig):
return singledb_config

def convert_blueprint(self, bp: AbstractBlueprint):
for field_name, field_value in bp:
self.convert_object_recursive(getattr(bp, field_name))
converted_bp = bp.model_copy(deep=True)

return bp
for field_name, field_value in converted_bp:
self.convert_object_recursive(getattr(converted_bp, field_name))

return converted_bp

def convert_object_recursive(self, obj):
if isinstance(obj, BaseModel):
Expand Down
6 changes: 2 additions & 4 deletions snowddl/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -110,15 +110,13 @@ def remove_blueprint(self, bp: AbstractBlueprint):
del self.blueprints[bp.__class__][str(bp.full_name)]

def add_policy_reference(self, cls: Type[T_Blueprint], policy_name: AbstractIdentWithPrefix, ref: AbstractPolicyReference):
all_blueprints = self.blueprints.get(cls, {})

if "references" not in cls.model_fields:
raise ValueError(f"{cls.__name__} does not have field [references], probably not a policy")

if str(policy_name) not in all_blueprints:
if str(policy_name) not in self.blueprints[cls]:
raise ValueError(f"{cls.__name__} with name [{policy_name}] does not exist or was not defined yet")

all_blueprints[str(policy_name)].references.append(ref)
self.blueprints[cls][str(policy_name)].references.append(ref)

def add_error(self, path: Path, e: Exception):
self.errors.append(
Expand Down

0 comments on commit ed9f3ff

Please sign in to comment.