Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

move prefix warning to validate_model #98

Merged
merged 1 commit into from
Feb 1, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 11 additions & 6 deletions liminal/orm/base_model.py
Original file line number Diff line number Diff line change
@@ -35,7 +35,7 @@ class BaseModel(Generic[T], Base):

_existing_schema_warehouse_names: set[str] = set()
_existing_schema_names: set[str] = set()
_existing_schema_prefixes: set[str] = set()
_existing_schema_prefixes: list[str] = []

def __init_subclass__(cls, **kwargs: Any):
super().__init_subclass__(**kwargs)
@@ -55,10 +55,6 @@ def __init_subclass__(cls, **kwargs: Any):
raise ValueError(
f"Schema name '{cls.__schema_properties__.name}' is already used by another subclass."
)
if cls.__schema_properties__.prefix.lower() in cls._existing_schema_prefixes:
logger.warning(
f"Schema prefix '{cls.__schema_properties__.prefix}' is already used by another subclass. Please ensure fieldsets=True in BenchlingConnection you are updating/creating this schema."
)
# Validate constraints
if cls.__schema_properties__.constraint_fields:
column_wh_names = [
@@ -76,7 +72,7 @@ def __init_subclass__(cls, **kwargs: Any):

cls._existing_schema_warehouse_names.add(warehouse_name)
cls._existing_schema_names.add(cls.__schema_properties__.name)
cls._existing_schema_prefixes.add(cls.__schema_properties__.prefix.lower())
cls._existing_schema_prefixes.append(cls.__schema_properties__.prefix.lower())

@declared_attr
def creator_id(cls) -> SqlColumn:
@@ -148,6 +144,15 @@ def validate_model(cls) -> bool:
model_columns = cls.get_columns_dict(exclude_base_columns=True)
properties = {n: c.properties for n, c in model_columns.items()}
errors = []
if (
cls._existing_schema_prefixes.count(
cls.__schema_properties__.prefix.lower()
)
> 1
):
logger.warning(
f"{cls.__name__}: schema prefix '{cls.__schema_properties__.prefix}' is already used by another subclass. Please ensure fieldsets=True in BenchlingConnection you are updating/creating this schema."
)
for wh_name, field in properties.items():
try:
field.validate_column(wh_name)