From 4c37ba6aa3b00f2c76d6e1e06ca24694717d2134 Mon Sep 17 00:00:00 2001 From: CBroz1 Date: Fri, 29 Mar 2024 17:02:51 -0500 Subject: [PATCH] Partial solve of #886 - Ask import --- src/spyglass/utils/dj_merge_tables.py | 2 +- src/spyglass/utils/dj_mixin.py | 7 ++++++- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/src/spyglass/utils/dj_merge_tables.py b/src/spyglass/utils/dj_merge_tables.py index 6aef132dd..48e8b3549 100644 --- a/src/spyglass/utils/dj_merge_tables.py +++ b/src/spyglass/utils/dj_merge_tables.py @@ -27,7 +27,7 @@ def is_merge_table(table): """Return True if table definition matches the default Merge table.""" this_def = re.sub( # First remove comments, then blank lines - r"\n\s*\n", "\n", re.sub(r"#.*\n", "\n", table.definition) + r"\n\s*\n", "\n", re.sub(r"#.*\n", "\n", str(table.heading)) ) return this_def == MERGE_DEFINITION diff --git a/src/spyglass/utils/dj_mixin.py b/src/spyglass/utils/dj_mixin.py index a805e3435..e152458f1 100644 --- a/src/spyglass/utils/dj_mixin.py +++ b/src/spyglass/utils/dj_mixin.py @@ -9,6 +9,7 @@ from datajoint.logging import logger as dj_logger from datajoint.table import Table from datajoint.utils import get_master, user_choice +from networkx import NetworkXError from pymysql.err import DataError from spyglass.utils.database_settings import SHARED_MODULES @@ -150,7 +151,11 @@ def search_descendants(parent): merge_tables[master_name] = master_ft search_descendants(master_ft) - _ = search_descendants(self) + try: + _ = search_descendants(self) + except NetworkXError as e: + table_name = "".join(e.args[0].split("`")[1:4]) + raise ValueError(f"Please import {table_name} and try again.") logger.info( f"Building merge cache for {self.table_name}.\n\t"