Skip to content

Commit

Permalink
Disable enforcement of update_support when running migrations
Browse files Browse the repository at this point in the history
  • Loading branch information
dgarros committed Aug 2, 2024
1 parent de6f232 commit 32d3585
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 6 deletions.
2 changes: 1 addition & 1 deletion backend/infrahub/cli/db.py
Original file line number Diff line number Diff line change
Expand Up @@ -210,7 +210,7 @@ async def update_core_schema( # pylint: disable=too-many-statements
candidate_schema.load_schema(schema=SchemaRoot(**deprecated_models))
candidate_schema.process()

result = branch_schema.validate_update(other=candidate_schema)
result = branch_schema.validate_update(other=candidate_schema, enforce_update_support=False)
if result.errors:
rprint(f"{error_badge} | Unable to update the schema, due to failed validations")
for error in result.errors:
Expand Down
7 changes: 4 additions & 3 deletions backend/infrahub/core/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -135,11 +135,12 @@ class SchemaUpdateValidationResult(BaseModel):
errors: list[SchemaUpdateValidationError] = Field(default_factory=list)
constraints: list[SchemaUpdateConstraintInfo] = Field(default_factory=list)
migrations: list[SchemaUpdateMigrationInfo] = Field(default_factory=list)
enforce_update_support: bool = True
diff: SchemaDiff

@classmethod
def init(cls, diff: SchemaDiff, schema: SchemaBranch) -> Self:
obj = cls(diff=diff)
def init(cls, diff: SchemaDiff, schema: SchemaBranch, enforce_update_support: bool = True) -> Self:
obj = cls(diff=diff, enforce_update_support=enforce_update_support)
obj.process_diff(schema=schema)

return obj
Expand Down Expand Up @@ -244,7 +245,7 @@ def _process_field(
schema_path: SchemaPath,
field_update: str,
) -> None:
if field_update == UpdateSupport.NOT_SUPPORTED.value:
if field_update == UpdateSupport.NOT_SUPPORTED.value and self.enforce_update_support:
self.errors.append(
SchemaUpdateValidationError(
path=schema_path,
Expand Down
6 changes: 4 additions & 2 deletions backend/infrahub/core/schema_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -251,9 +251,11 @@ def update(self, schema: SchemaBranch) -> None:
# else:
# del self.generics[item_kind]

def validate_update(self, other: SchemaBranch) -> SchemaUpdateValidationResult:
def validate_update(self, other: SchemaBranch, enforce_update_support: bool = True) -> SchemaUpdateValidationResult:
diff = self.diff(other=other)
result = SchemaUpdateValidationResult.init(diff=diff, schema=other)
result = SchemaUpdateValidationResult.init(
diff=diff, schema=other, enforce_update_support=enforce_update_support
)
result.validate_all(migration_map=MIGRATION_MAP, validator_map=CONSTRAINT_VALIDATOR_MAP)
return result

Expand Down

0 comments on commit 32d3585

Please sign in to comment.