Skip to content

Commit 7523b97

Browse files
committed
♻️ Also account for confest module
1 parent 17cd576 commit 7523b97

File tree

1 file changed

+15
-11
lines changed

1 file changed

+15
-11
lines changed

lamindb_setup/_connect_instance.py

Lines changed: 15 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -196,18 +196,22 @@ def reset_django_module_variables():
196196
from django.apps import apps
197197

198198
app_names = {app.name for app in apps.get_app_configs()}
199-
main_modules = {
200-
k: v
201-
for k, v in vars(sys.modules["__main__"]).items()
202-
if isinstance(v, types.ModuleType)
203-
and not k.startswith("_")
204-
and v.__name__ in app_names
205-
}
206199

207-
for var_name, old_module in main_modules.items():
208-
module_name = old_module.__name__
209-
if module_name in sys.modules:
210-
vars(sys.modules["__main__"])[var_name] = sys.modules[module_name]
200+
# Check both __main__ and conftest
201+
for module_name in ["__main__", "conftest"]:
202+
if module_name not in sys.modules:
203+
continue
204+
205+
module = sys.modules[module_name]
206+
for k, v in vars(module).items():
207+
if (
208+
isinstance(v, types.ModuleType)
209+
and not k.startswith("_")
210+
and getattr(v, "__name__", None) in app_names
211+
):
212+
# Update the module where we found the variable
213+
if v.__name__ in sys.modules:
214+
vars(module)[k] = sys.modules[v.__name__]
211215

212216

213217
@unlock_cloud_sqlite_upon_exception(ignore_prev_locker=True)

0 commit comments

Comments
 (0)