Skip to content

Commit

Permalink
fix: force casefold, number of arguments for unset tag
Browse files Browse the repository at this point in the history
  • Loading branch information
pquadri committed Jul 17, 2024
1 parent 86fa36f commit 7d91acd
Showing 1 changed file with 11 additions and 3 deletions.
14 changes: 11 additions & 3 deletions snowflake_utils/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
from enum import Enum
from functools import partial

from pydantic import BaseModel, Field
from pydantic import BaseModel, Field, field_validator
from snowflake.connector.cursor import SnowflakeCursor
from typing_extensions import Self

Expand Down Expand Up @@ -65,6 +65,11 @@ def parsed_columns(self):
def parse_from_json(self):
raise NotImplementedError("Not implemented yet")

@field_validator("columns")
@classmethod
def force_columns_to_casefold(cls, value) -> dict:
return {k.casefold(): v for k, v in value.items()}


class Schema(BaseModel):
name: str
Expand Down Expand Up @@ -397,12 +402,15 @@ def sync_tags(self, cursor: SnowflakeCursor) -> None:
desired_tags = {
f"{column}.{tag_name}.{tag_value}".casefold(): (column, tag_name, tag_value)
for column in self.table_structure.columns
for tag_name, tag_value in self.table_structure.columns[column].tags.items()
for tag_name, tag_value in self.table_structure.columns[
column.casefold()
].tags.items()
}

for tag in existing_tags:
if tag not in desired_tags:
self._unset_tag(cursor, *existing_tags[tag])
column, tag_name, _value = existing_tags[tag]
self._unset_tag(cursor, column, tag_name)

for tag in desired_tags:
if tag not in existing_tags:
Expand Down

0 comments on commit 7d91acd

Please sign in to comment.