Skip to content

🚸 Set up Django on every import of lamindb via a "mock instance" #1063

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

Open
wants to merge 40 commits into
base: main
Choose a base branch
from

Conversation

falexwolf
Copy link
Member

@falexwolf falexwolf commented Jun 16, 2025

The change here should allow us to eliminate the conditional import in the lamindb root module.

This PR fixes several issues with the reset logic introduced here:

Stale class issue: https://claude.ai/share/b4b3dcb5-4685-42dc-8e32-50851d41c5ac

Copy link

codecov bot commented Jun 16, 2025

Codecov Report

Attention: Patch coverage is 87.65432% with 10 lines in your changes missing coverage. Please review.

Project coverage is 85.47%. Comparing base (903192f) to head (b2a1f92).

Files with missing lines Patch % Lines
lamindb_setup/_check_setup.py 86.36% 3 Missing ⚠️
lamindb_setup/_cache.py 33.33% 2 Missing ⚠️
lamindb_setup/_connect_instance.py 93.54% 2 Missing ⚠️
lamindb_setup/_init_instance.py 50.00% 2 Missing ⚠️
lamindb_setup/core/_settings_instance.py 83.33% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #1063      +/-   ##
==========================================
- Coverage   85.58%   85.47%   -0.11%     
==========================================
  Files          45       45              
  Lines        3905     3953      +48     
==========================================
+ Hits         3342     3379      +37     
- Misses        563      574      +11     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

Copy link

github-actions bot commented Jun 16, 2025

@github-actions github-actions bot temporarily deployed to pull request June 16, 2025 15:17 Inactive
@github-actions github-actions bot temporarily deployed to pull request June 16, 2025 16:34 Inactive
@falexwolf falexwolf changed the title 🚸 Always connect 🚸 Use dummy database so that we can always set up django to import the whole of lamindb Jun 16, 2025
@github-actions github-actions bot temporarily deployed to pull request June 16, 2025 17:18 Inactive
@github-actions github-actions bot temporarily deployed to pull request June 16, 2025 17:55 Inactive
@falexwolf falexwolf changed the title 🚸 Use dummy database so that we can always set up django to import the whole of lamindb 🚸 Always import all of lamindb Jun 17, 2025
@github-actions github-actions bot temporarily deployed to pull request June 17, 2025 06:21 Inactive
@falexwolf falexwolf changed the title 🚸 Always import all of lamindb 🚸 Set up Django on every import of lamindb Jun 17, 2025
@github-actions github-actions bot temporarily deployed to pull request June 17, 2025 06:47 Inactive
@falexwolf falexwolf changed the title 🚸 Set up Django on every import of lamindb 🚸 Set up Django on every import of lamindb by providing a "mock instance" Jun 17, 2025
@github-actions github-actions bot temporarily deployed to pull request June 30, 2025 11:08 Inactive
@@ -339,6 +340,7 @@ def init(
if _write_settings:
settings.auto_connect = True
importlib.reload(importlib.import_module("lamindb"))
reset_django_module_variables()
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i don't think it should always reset, it should do the reset only on re-connect. Also not clear why importlib.reload deosn't do this already.

@github-actions github-actions bot temporarily deployed to pull request June 30, 2025 13:47 Inactive
@github-actions github-actions bot temporarily deployed to pull request July 1, 2025 10:16 Inactive
@github-actions github-actions bot temporarily deployed to pull request July 1, 2025 18:52 Inactive
@github-actions github-actions bot temporarily deployed to pull request July 1, 2025 19:07 Inactive
@github-actions github-actions bot temporarily deployed to pull request July 1, 2025 19:38 Inactive
@falexwolf
Copy link
Member Author

I think that very likely we can also eliminate the whole disable_auto_connect() logic if we eliminate the whole "module reload" logic. All of this stuff is only there because of how complicated the import of lamindb was.

But these simplifications can also go into another PR, I guess. 🤔

@github-actions github-actions bot temporarily deployed to pull request July 1, 2025 20:13 Inactive
@github-actions github-actions bot temporarily deployed to pull request July 2, 2025 08:50 Inactive
@github-actions github-actions bot temporarily deployed to pull request July 2, 2025 10:29 Inactive
@github-actions github-actions bot temporarily deployed to pull request July 2, 2025 10:58 Inactive
@github-actions github-actions bot temporarily deployed to pull request July 2, 2025 11:34 Inactive
falexwolf and others added 3 commits July 6, 2025 21:35
…n process (#1077)

* Allow to re-connect in the same process

* allow to init

* fix

* correct test

---------

Co-authored-by: Koncopd <[email protected]>
@github-actions github-actions bot temporarily deployed to pull request July 20, 2025 09:48 Inactive
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants