Skip to content
Closed
Show file tree
Hide file tree
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
4 changes: 2 additions & 2 deletions mostlyai/sdk/_data/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,7 @@ def get_context_key(self, table_name: str) -> DataIdentifier | None:

def get_primary_key(self, table_name: str) -> DataIdentifier | None:
primary_key = None
if self.tables[table_name].primary_key is not None:
if self.tables[table_name].primary_key:
# first, check primary key on table
primary_key = DataIdentifier(table_name, self.tables[table_name].primary_key)
elif context_relations := self.get_child_context_relations(table_name):
Expand Down Expand Up @@ -260,7 +260,7 @@ def get_scp_relations(self, table: str) -> list[ContextRelation]:

def _update_key_encoding_types(self) -> None:
for tbl_name, tbl_table in self.tables.items():
if tbl_table.primary_key is not None:
if tbl_table.primary_key:
if tbl_table.primary_key in tbl_table.encoding_types:
del tbl_table.encoding_types[tbl_table.primary_key]
for rel in self.get_relations_to_table(tbl_name):
Expand Down
4 changes: 2 additions & 2 deletions mostlyai/sdk/_data/pull_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -448,7 +448,7 @@ def fetch_table_data(
)
n_fetched_rows = 0
for idx, chunk_df in enumerate(iterator):
if deduplicate_pks and primary_key is not None and primary_key.column in chunk_df.columns:
if deduplicate_pks and primary_key and primary_key.column in chunk_df.columns:
# consider only the first occurrence of each primary key
if not chunk_df[primary_key.column].is_unique:
drop_idx = chunk_df[primary_key.column].duplicated()
Expand Down Expand Up @@ -568,7 +568,7 @@ def fetch_target_table(
key_fraction_df[FRACTION] = keys[MAX_TGT_ROWS_PER_CTX_KEY] / schema.tables[tgt].row_count
key_fraction_df = key_fraction_df.rename(columns={tgt_context_key.ref_name(): tgt_context_key.column})
key_fraction_df = key_fraction_df.drop(columns=[MAX_TGT_ROWS_PER_CTX_KEY])
elif tgt_primary_key is not None:
elif tgt_primary_key:
# flat setup with primary key
# sample target table by target primary key
# use provided keys to filter and order the target table (max_sample_size=None, do_shuffle=False)
Expand Down
6 changes: 3 additions & 3 deletions mostlyai/sdk/domain.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
# limitations under the License.

# generated by datamodel-codegen:
# timestamp: 2025-06-26T08:04:20+00:00
# timestamp: 2025-07-09T15:31:45+00:00

from __future__ import annotations

Expand Down Expand Up @@ -2735,7 +2735,7 @@ def validate_keys_exists_in_columns(cls, values):
if values.columns:
column_names = {col.name for col in values.columns}
pk = values.primary_key
if pk is not None and pk not in column_names:
if pk and pk not in column_names:
raise ValueError(f"Primary key column '{pk}' does not exist in the table's columns.")
for fk in values.foreign_keys or []:
if fk.column not in column_names:
Expand All @@ -2747,7 +2747,7 @@ def validate_keys_exists_in_columns(cls, values):
def validate_pk_and_fks_are_not_overlapping(cls, values):
primary_key = values.primary_key
foreign_keys = [fk.column for fk in values.foreign_keys or []]
if primary_key is not None and primary_key in foreign_keys:
if primary_key and primary_key in foreign_keys:
raise ValueError(f"Column '{primary_key}' is both a primary key and a foreign key.")
return values

Expand Down
4 changes: 2 additions & 2 deletions tools/custom_template/pydantic_v2/BaseModel.jinja2
Original file line number Diff line number Diff line change
Expand Up @@ -786,7 +786,7 @@ class {{ class_name }}({{ base_class }}):{% if comment is defined %} # {{ comme
if values.columns:
column_names = {col.name for col in values.columns}
pk = values.primary_key
if pk is not None and pk not in column_names:
if pk and pk not in column_names:
raise ValueError(f"Primary key column '{pk}' does not exist in the table's columns.")
for fk in values.foreign_keys or []:
if fk.column not in column_names:
Expand All @@ -798,7 +798,7 @@ class {{ class_name }}({{ base_class }}):{% if comment is defined %} # {{ comme
def validate_pk_and_fks_are_not_overlapping(cls, values):
primary_key = values.primary_key
foreign_keys = [fk.column for fk in values.foreign_keys or []]
if primary_key is not None and primary_key in foreign_keys:
if primary_key and primary_key in foreign_keys:
raise ValueError(f"Column '{primary_key}' is both a primary key and a foreign key.")
return values
{%- endif %}{%- if class_name == "SyntheticTableConfiguration" %}
Expand Down
4 changes: 2 additions & 2 deletions tools/model.py
Original file line number Diff line number Diff line change
Expand Up @@ -600,7 +600,7 @@ def validate_keys_exists_in_columns(cls, values):
if values.columns:
column_names = {col.name for col in values.columns}
pk = values.primary_key
if pk is not None and pk not in column_names:
if pk and pk not in column_names:
raise ValueError(f"Primary key column '{pk}' does not exist in the table's columns.")
for fk in values.foreign_keys or []:
if fk.column not in column_names:
Expand All @@ -612,7 +612,7 @@ def validate_keys_exists_in_columns(cls, values):
def validate_pk_and_fks_are_not_overlapping(cls, values):
primary_key = values.primary_key
foreign_keys = [fk.column for fk in values.foreign_keys or []]
if primary_key is not None and primary_key in foreign_keys:
if primary_key and primary_key in foreign_keys:
raise ValueError(f"Column '{primary_key}' is both a primary key and a foreign key.")
return values

Expand Down