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

translation link bugfix #106

Merged
merged 3 commits into from
Feb 11, 2025
Merged
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
2 changes: 1 addition & 1 deletion liminal/entity_schemas/generate_files.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 in BenchlingFieldType.get_entity_link_types()
and col.entity_link is not None
):
if not col.is_multi:
Expand Down
2 changes: 1 addition & 1 deletion liminal/entity_schemas/tag_schema_models.py
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
4 changes: 4 additions & 0 deletions liminal/enums/benchling_field_type.py
Original file line number Diff line number Diff line change
Expand Up @@ -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]
7 changes: 5 additions & 2 deletions liminal/mappers.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -48,14 +50,15 @@ 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,
BenchlingFieldType.LONG_TEXT: String,
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:
Expand Down Expand Up @@ -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,
Expand Down
10 changes: 5 additions & 5 deletions liminal/orm/column.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
if entity_link and type not in BenchlingFieldType.get_entity_link_types():
raise ValueError(
"Entity 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 != BenchlingFieldType.ENTITY_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."
"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
Expand Down