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 35 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 88.15789% with 9 lines in your changes missing coverage. Please review.

Project coverage is 85.21%. Comparing base (6864293) to head (a943bcc).

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 92.59% 2 Missing ⚠️
lamindb_setup/core/_settings.py 88.88% 1 Missing ⚠️
lamindb_setup/core/_settings_instance.py 83.33% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #1063      +/-   ##
==========================================
+ Coverage   85.10%   85.21%   +0.10%     
==========================================
  Files          45       45              
  Lines        3747     3794      +47     
==========================================
+ Hits         3189     3233      +44     
- Misses        558      561       +3     

☔ 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
@falexwolf
Copy link
Member Author

It is ready!

@falexwolf falexwolf requested a review from Koncopd July 1, 2025 17:25
@Koncopd
Copy link
Member

Koncopd commented Jul 1, 2025

I see the the tests still fail on lamindb.

@github-actions github-actions bot temporarily deployed to pull request July 1, 2025 17:39 Inactive
@falexwolf
Copy link
Member Author

I see the the tests still fail on lamindb.

That was something trivial related to refactoring the error behavior.

@Koncopd
Copy link
Member

Koncopd commented Jul 1, 2025

Got it, I will check tmr morning.

@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
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