From 2c51d0667c6bdf1cdb00ed98a21a6554b3084877 Mon Sep 17 00:00:00 2001 From: ndamania00 Date: Mon, 10 Feb 2025 19:42:43 -0500 Subject: [PATCH 1/3] translation link bugfix --- liminal/mappers.py | 7 +++++-- liminal/orm/column.py | 8 ++++---- 2 files changed, 9 insertions(+), 6 deletions(-) diff --git a/liminal/mappers.py b/liminal/mappers.py index ac99034..fd9cad2 100644 --- a/liminal/mappers.py +++ b/liminal/mappers.py @@ -22,6 +22,8 @@ def convert_benchling_type_to_python_type(benchling_type: BenchlingFieldType) -> BenchlingFieldType.BLOB_LINK: dict[str, Any], BenchlingFieldType.CUSTOM_ENTITY_LINK: str, BenchlingFieldType.DNA_SEQUENCE_LINK: str, + BenchlingFieldType.AA_SEQUENCE_LINK: str, + BenchlingFieldType.TRANSLATION_LINK: str, BenchlingFieldType.DROPDOWN: str, BenchlingFieldType.ENTITY_LINK: str, BenchlingFieldType.ENTRY_LINK: str, @@ -48,6 +50,8 @@ def convert_benchling_type_to_sql_alchemy_type( BenchlingFieldType.BLOB_LINK: JSON, BenchlingFieldType.CUSTOM_ENTITY_LINK: String, BenchlingFieldType.DNA_SEQUENCE_LINK: String, + BenchlingFieldType.AA_SEQUENCE_LINK: String, + BenchlingFieldType.TRANSLATION_LINK: String, BenchlingFieldType.DROPDOWN: String, BenchlingFieldType.ENTITY_LINK: String, BenchlingFieldType.ENTRY_LINK: String, @@ -55,7 +59,6 @@ def convert_benchling_type_to_sql_alchemy_type( BenchlingFieldType.STORAGE_LINK: String, BenchlingFieldType.PART_LINK: String, BenchlingFieldType.MIXTURE_LINK: String, - BenchlingFieldType.AA_SEQUENCE_LINK: String, BenchlingFieldType.TEXT: String, } if benchling_type in benchling_to_sql_alchemy_type_map: @@ -141,7 +144,7 @@ def convert_api_field_type_to_field_type( ): BenchlingFieldType.PART_LINK, ( BenchlingAPIFieldType.TRANSLATION_LINK, - BenchlingFolderItemType.SEQUENCE, + None, ): BenchlingFieldType.TRANSLATION_LINK, (BenchlingAPIFieldType.FILE_LINK, None): BenchlingFieldType.ENTITY_LINK, (BenchlingAPIFieldType.FLOAT, None): BenchlingFieldType.DECIMAL, diff --git a/liminal/orm/column.py b/liminal/orm/column.py index 1527194..22be2e8 100644 --- a/liminal/orm/column.py +++ b/liminal/orm/column.py @@ -73,10 +73,10 @@ def __init__( raise ValueError("Dropdown can only be set if the field type is DROPDOWN.") if dropdown is None and type == BenchlingFieldType.DROPDOWN: raise ValueError("Dropdown must be set if the field type is DROPDOWN.") - if entity_link and type != BenchlingFieldType.ENTITY_LINK: - raise ValueError( - "Entity link can only be set if the field type is ENTITY_LINK." - ) + # if entity_link and type != BenchlingFieldType.ENTITY_LINK: + # raise ValueError( + # "Entity link can only be set if the field type is ENTITY_LINK." + # ) if parent_link and type != BenchlingFieldType.ENTITY_LINK: raise ValueError( "Parent link can only be set if the field type is ENTITY_LINK." From d9c37b276bb051926d1274d2f44a67b5115faa9a Mon Sep 17 00:00:00 2001 From: ndamania00 Date: Mon, 10 Feb 2025 20:30:39 -0500 Subject: [PATCH 2/3] entity link logic across codebase --- liminal/entity_schemas/generate_files.py | 2 +- liminal/entity_schemas/tag_schema_models.py | 2 +- liminal/enums/benchling_field_type.py | 4 ++++ liminal/orm/column.py | 14 +++++++------- 4 files changed, 13 insertions(+), 9 deletions(-) diff --git a/liminal/entity_schemas/generate_files.py b/liminal/entity_schemas/generate_files.py index da87c38..9dbeb17 100644 --- a/liminal/entity_schemas/generate_files.py +++ b/liminal/entity_schemas/generate_files.py @@ -105,7 +105,7 @@ def generate_all_entity_schema_files( if not has_date: import_strings.append("from datetime import datetime") if ( - col.type == BenchlingFieldType.ENTITY_LINK + col.type == BenchlingFieldType.get_entity_link_types() and col.entity_link is not None ): if not col.is_multi: diff --git a/liminal/entity_schemas/tag_schema_models.py b/liminal/entity_schemas/tag_schema_models.py index d24994b..b0dba4f 100644 --- a/liminal/entity_schemas/tag_schema_models.py +++ b/liminal/entity_schemas/tag_schema_models.py @@ -164,7 +164,7 @@ def from_props( ) tagSchema = None - if new_props.type == BenchlingFieldType.ENTITY_LINK: + if new_props.type in BenchlingFieldType.get_entity_link_types(): if new_props.entity_link is not None: if benchling_service is None: raise ValueError( diff --git a/liminal/enums/benchling_field_type.py b/liminal/enums/benchling_field_type.py index 818823b..da877f6 100644 --- a/liminal/enums/benchling_field_type.py +++ b/liminal/enums/benchling_field_type.py @@ -32,3 +32,7 @@ def get_non_multi_select_types(cls) -> list[str]: cls.DATE, cls.DATETIME, ] + + @classmethod + def get_entity_link_types(cls) -> list[str]: + return [cls.ENTITY_LINK, cls.TRANSLATION_LINK] diff --git a/liminal/orm/column.py b/liminal/orm/column.py index 22be2e8..a294dfa 100644 --- a/liminal/orm/column.py +++ b/liminal/orm/column.py @@ -73,19 +73,19 @@ def __init__( raise ValueError("Dropdown can only be set if the field type is DROPDOWN.") if dropdown is None and type == BenchlingFieldType.DROPDOWN: raise ValueError("Dropdown must be set if the field type is DROPDOWN.") - # if entity_link and type != BenchlingFieldType.ENTITY_LINK: - # raise ValueError( - # "Entity link can only be set if the field type is ENTITY_LINK." - # ) - if parent_link and type != BenchlingFieldType.ENTITY_LINK: + if entity_link and type not in BenchlingFieldType.get_entity_link_types(): raise ValueError( - "Parent link can only be set if the field type is ENTITY_LINK." + "Entity link can only be set if the field type is ENTITY_LINK or TRANSLATION_LINK." + ) + if parent_link and type not in BenchlingFieldType.get_entity_link_types(): + raise ValueError( + "Parent link can only be set if the field type is ENTITY_LINK or TRANSLATION_LINK." ) if type in BenchlingFieldType.get_non_multi_select_types() and is_multi is True: raise ValueError(f"Field type {type} cannot have multi-value set as True.") self.sqlalchemy_type = sqlalchemy_type foreign_key = None - if type == BenchlingFieldType.ENTITY_LINK and entity_link: + if type in BenchlingFieldType.get_entity_link_types() and entity_link: foreign_key = ForeignKey(f"{entity_link}$raw.id") if _warehouse_name: kwargs["name"] = _warehouse_name From e3f7f33bf843d09ebaaaa382ce946e3e83283b9a Mon Sep 17 00:00:00 2001 From: ndamania00 Date: Mon, 10 Feb 2025 20:34:21 -0500 Subject: [PATCH 3/3] in --- liminal/entity_schemas/generate_files.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/liminal/entity_schemas/generate_files.py b/liminal/entity_schemas/generate_files.py index 9dbeb17..d1f84a6 100644 --- a/liminal/entity_schemas/generate_files.py +++ b/liminal/entity_schemas/generate_files.py @@ -105,7 +105,7 @@ def generate_all_entity_schema_files( if not has_date: import_strings.append("from datetime import datetime") if ( - col.type == BenchlingFieldType.get_entity_link_types() + col.type in BenchlingFieldType.get_entity_link_types() and col.entity_link is not None ): if not col.is_multi: