Skip to content

Commit

Permalink
fix dropdown generate files to ignore archived
Browse files Browse the repository at this point in the history
  • Loading branch information
ndamania00 committed Oct 25, 2024
1 parent a282fab commit 1bc8d50
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 16 deletions.
2 changes: 1 addition & 1 deletion liminal/dropdowns/compare.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ def compare_dropdowns(
) -> dict[str, list[CompareOperation]]:
dropdown_operations: dict[str, list[CompareOperation]] = {}
benchling_dropdowns: dict[str, Dropdown] = get_benchling_dropdowns_dict(
benchling_service
benchling_service, include_archived=True
)
processed_benchling_names = set()
model_dropdowns = BaseDropdown.get_all_subclasses(dropdown_names)
Expand Down
35 changes: 25 additions & 10 deletions liminal/dropdowns/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,15 +57,15 @@ def get_benchling_dropdown_by_name(

def get_benchling_dropdowns_dict(
benchling_service: BenchlingService,
include_archived: bool = False,
) -> dict[str, Dropdown]:
with requests.Session() as session:
request = session.get(
f"https://{benchling_service.benchling_tenant}.benchling.com/1/api/schema-field-selectors/?registryId={benchling_service.registry_id}",
headers=benchling_service.custom_post_headers,
cookies=benchling_service.custom_post_cookies,
)
return {
d["name"]: Dropdown(
def _convert_dropdown_from_json(
d: dict[str, Any], include_archived: bool = False
) -> Dropdown:
all_options = d["allSchemaFieldSelectorOptions"]
if not include_archived:
all_options = [o for o in all_options if not o["archiveRecord"]]
return Dropdown(
id=d["id"],
name=d["name"],
archive_record=BenchlingArchiveRecord(reason=d["archiveRecord"]["purpose"])
Expand All @@ -81,11 +81,26 @@ def get_benchling_dropdowns_dict(
if o["archiveRecord"]
else None,
)
for o in d["allSchemaFieldSelectorOptions"]
for o in all_options
],
)
for d in request.json()["selectorsByRegistryId"][benchling_service.registry_id]

with requests.Session() as session:
request = session.get(
f"https://{benchling_service.benchling_tenant}.benchling.com/1/api/schema-field-selectors/?registryId={benchling_service.registry_id}",
headers=benchling_service.custom_post_headers,
cookies=benchling_service.custom_post_cookies,
)
all_dropdowns = request.json()["selectorsByRegistryId"][
benchling_service.registry_id
]
if not include_archived:
all_dropdowns = [d for d in all_dropdowns if not d["archiveRecord"]]
dropdowns = {
d["name"]: _convert_dropdown_from_json(d, include_archived)
for d in all_dropdowns
}
return dropdowns


def dropdown_exists_in_benchling(
Expand Down
9 changes: 4 additions & 5 deletions liminal/entity_schemas/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,9 @@ def convert_tag_schema_to_internal_schema(
dropdowns_map: dict[str, str],
include_archived_fields: bool = False,
) -> tuple[SchemaProperties, dict[str, BaseFieldProperties]]:
all_fields = tag_schema.allFields
if not include_archived_fields:
all_fields = [f for f in all_fields if not f.archiveRecord]
return (
SchemaProperties(
name=tag_schema.name,
Expand All @@ -63,11 +66,7 @@ def convert_tag_schema_to_internal_schema(
).set_archived(tag_schema.archiveRecord is not None),
{
f.systemName: convert_tag_schema_field_to_field_properties(f, dropdowns_map)
for f in (
tag_schema.allFields
if include_archived_fields
else [f for f in tag_schema.allFields if not f.archiveRecord]
)
for f in all_fields
},
)

Expand Down

0 comments on commit 1bc8d50

Please sign in to comment.