From bb75752cda353bc78fe3ea3985be134a8e476dce Mon Sep 17 00:00:00 2001 From: hanars Date: Thu, 13 Aug 2026 12:11:30 -0400 Subject: [PATCH 1/3] lazy import models for clickhouse reload command --- .../management/commands/reload_clinvar_all_variants.py | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/clickhouse_search/management/commands/reload_clinvar_all_variants.py b/clickhouse_search/management/commands/reload_clinvar_all_variants.py index d343e9dd2e..6233490640 100644 --- a/clickhouse_search/management/commands/reload_clinvar_all_variants.py +++ b/clickhouse_search/management/commands/reload_clinvar_all_variants.py @@ -13,8 +13,6 @@ from typing import Optional, Union from clickhouse_backend import models -from clickhouse_search.models.reference_data_models import ClinvarAllVariantsGRCh37SnvIndel, ClinvarAllVariantsSnvIndel, ClinvarAllVariantsMito, \ - ClinvarMvGRCh37SnvIndel, ClinvarMvSnvIndel, ClinvarMvMito, ClinvarSearchMvGRCh37SnvIndel, ClinvarSearchMvSnvIndel, ClinvarSearchMvMito from clickhouse_search.constants import \ CLINVAR_ASSERTIONS as CORE_CLINVAR_ASSERTIONS, CLINVAR_PATHOGENICITIES as CORE_CLINVAR_PATHOGENICITIES, CLINVAR_DEFAULT_PATHOGENICITY as CORE_CLINVAR_DEFAULT_PATHOGENICITY, \ CLINVAR_CONFLICTING_CLASSICATIONS_OF_PATHOGENICITY as CORE_CLINVAR_CONFLICTING_CLASSICATIONS_OF_PATHOGENICITY @@ -200,6 +198,8 @@ def parse_submitters_and_conditions(classified_record_node: xml) -> [list[str], return submitters, conditions def extract_variant_info(elem: xml.etree.ElementTree.Element, new_version: str, unenumerated_value_alerts: Optional[list] = None) -> tuple[models.ClickhouseModel, models.ClickhouseModel, models.ClickhouseModel]: + from clickhouse_search.models.reference_data_models import ClinvarAllVariantsGRCh37SnvIndel, ClinvarAllVariantsSnvIndel, ClinvarAllVariantsMito + # Cannot use regular bool-falseyness here, as: # "An element with no child elements (even if it exists and has text) will be falsey." classified_record_node = elem.find('ClassifiedRecord') @@ -249,6 +249,8 @@ def extract_variant_info(elem: xml.etree.ElementTree.Element, new_version: str, ) def parse_clinvar_file(gzipped_file, existing_version_obj, model_to_batch, unenumerated_value_alerts): + from clickhouse_search.models.reference_data_models import ClinvarAllVariantsSnvIndel + for event, elem in ET.iterparse(gzipped_file, events=('start', 'end')): # Handle parsing the current date. if event == 'start' and elem.tag == 'ClinVarVariationRelease': @@ -286,6 +288,8 @@ class Command(BaseCommand): help = 'Reload all clinvar variants from weekly NCBI xml release' def handle(self, *args, **options): + from clickhouse_search.models.reference_data_models import ClinvarAllVariantsGRCh37SnvIndel, ClinvarAllVariantsSnvIndel, ClinvarAllVariantsMito, \ + ClinvarMvGRCh37SnvIndel, ClinvarMvSnvIndel, ClinvarMvMito, ClinvarSearchMvGRCh37SnvIndel, ClinvarSearchMvSnvIndel, ClinvarSearchMvMito model_to_batch = { ClinvarAllVariantsGRCh37SnvIndel: [], ClinvarAllVariantsSnvIndel: [], From 16ddba222c62a888900d3778aedf2958ada17731 Mon Sep 17 00:00:00 2001 From: hanars Date: Thu, 13 Aug 2026 12:23:12 -0400 Subject: [PATCH 2/3] codacy clean up --- .../management/commands/reload_clinvar_all_variants.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/clickhouse_search/management/commands/reload_clinvar_all_variants.py b/clickhouse_search/management/commands/reload_clinvar_all_variants.py index 6233490640..29bac87a93 100644 --- a/clickhouse_search/management/commands/reload_clinvar_all_variants.py +++ b/clickhouse_search/management/commands/reload_clinvar_all_variants.py @@ -199,7 +199,7 @@ def parse_submitters_and_conditions(classified_record_node: xml) -> [list[str], def extract_variant_info(elem: xml.etree.ElementTree.Element, new_version: str, unenumerated_value_alerts: Optional[list] = None) -> tuple[models.ClickhouseModel, models.ClickhouseModel, models.ClickhouseModel]: from clickhouse_search.models.reference_data_models import ClinvarAllVariantsGRCh37SnvIndel, ClinvarAllVariantsSnvIndel, ClinvarAllVariantsMito - + # Cannot use regular bool-falseyness here, as: # "An element with no child elements (even if it exists and has text) will be falsey." classified_record_node = elem.find('ClassifiedRecord') From 1a12fbc1cd8a08e2f2d2c3d9e3e1ff3fa464a069 Mon Sep 17 00:00:00 2001 From: hanars Date: Thu, 13 Aug 2026 12:37:39 -0400 Subject: [PATCH 3/3] codacy fix --- .../management/commands/reload_clinvar_all_variants.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/clickhouse_search/management/commands/reload_clinvar_all_variants.py b/clickhouse_search/management/commands/reload_clinvar_all_variants.py index 29bac87a93..2562b3c4d5 100644 --- a/clickhouse_search/management/commands/reload_clinvar_all_variants.py +++ b/clickhouse_search/management/commands/reload_clinvar_all_variants.py @@ -250,7 +250,7 @@ def extract_variant_info(elem: xml.etree.ElementTree.Element, new_version: str, def parse_clinvar_file(gzipped_file, existing_version_obj, model_to_batch, unenumerated_value_alerts): from clickhouse_search.models.reference_data_models import ClinvarAllVariantsSnvIndel - + for event, elem in ET.iterparse(gzipped_file, events=('start', 'end')): # Handle parsing the current date. if event == 'start' and elem.tag == 'ClinVarVariationRelease':