Skip to content
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

✨ Better error message if wetlab is not added to the current instance #97

Closed
wants to merge 2 commits into from

Conversation

Zethson
Copy link
Member

@Zethson Zethson commented Jan 16, 2025

Before:

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/home/lukas/code/lamindb/sub/wetlab/wetlab/__init__.py", line 73, in <module>
    from ._pert_curator import PertCurator
  File "/home/lukas/code/lamindb/sub/wetlab/wetlab/_pert_curator.py", line 24, in <module>
    from .models import (
  File "/home/lukas/code/lamindb/sub/wetlab/wetlab/models.py", line 59, in <module>
    class Compound(BioRecord, TracksRun, TracksUpdates):
  File "/home/lukas/code/lamindb/lamindb/models.py", line 575, in __new__
    new_class = super().__new__(cls, name, bases, attrs, **kwargs)
                ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/lukas/miniforge3/envs/lamindb/lib/python3.12/site-packages/django/db/models/base.py", line 134, in __new__
    raise RuntimeError(
RuntimeError: Model class wetlab.models.Compound doesn't declare an explicit app_label and isn't in an application in INSTALLED_APPS.

After:

---------------------------------------------------------------------------
RuntimeError                              Traceback (most recent call last)
File ~/code/wetlab/wetlab/__init__.py:74
     73 try:
---> 74   from ._pert_curator import PertCurator
     75   from .models import (
     76      Biologic,
     77      Biosample,
   (...)
     87      Well,
     88   )

File ~/code/wetlab/wetlab/_pert_curator.py:24
     19             raise RuntimeError(
     20                 "cellxgene_lamin is not installed. Please install it to use PertCurator."
     21             )
---> 24 from .models import (
     25     Biologic,
     26     Compound,
     27     Donor,
     28     EnvironmentalPerturbation,
     29     GeneticPerturbation,
     30     PerturbationTarget,
     31 )
     33 if TYPE_CHECKING:

File ~/code/wetlab/wetlab/models.py:59
     47 # def _get_related_repr(instance, related_name: str) -> str:
     48 #     try:
     49 #         related_manager = getattr(instance, related_name)
   (...)
     55 #         return ""
     56 #     return ""
---> 59 class Compound(BioRecord, TracksRun, TracksUpdates):
     60     """Models a (chemical) compound such as a drug.
     61 
     62     Examples:
   (...)
     66         ... ).save()
     67     """

File ~/code/lamindb/lamindb/models.py:575, in Registry.__new__(cls, name, bases, attrs, **kwargs)
    574 def __new__(cls, name, bases, attrs, **kwargs):
--> 575     new_class = super().__new__(cls, name, bases, attrs, **kwargs)
    576     return new_class

File ~/miniforge3/envs/lamindb/lib/python3.12/site-packages/django/db/models/base.py:134, in ModelBase.__new__(cls, name, bases, attrs, **kwargs)
    133     if not abstract:
--> 134         raise RuntimeError(
    135             "Model class %s.%s doesn't declare an explicit "
    136             "app_label and isn't in an application in "
    137             "INSTALLED_APPS." % (module, name)
    138         )
    140 else:

RuntimeError: Model class wetlab.models.Compound doesn't declare an explicit app_label and isn't in an application in INSTALLED_APPS.

The above exception was the direct cause of the following exception:

RuntimeError                              Traceback (most recent call last)
Cell In[1], line 3
      1 import lamindb as ln
      2 import bionty as bt
----> 3 import wetlab as wl
      5 ln.track()

File ~/code/wetlab/wetlab/__init__.py:91
     89 except RuntimeError as e:
     90   if "isn't in an application in INSTALLED_APPS" in str(e):
---> 91      raise RuntimeError(
     92            "Add wetlab to your instance using: import lamindb as ln; ln.settings.add_app('wetlab')"
     93      ) from e
     94   raise

RuntimeError: the 'wetlab' module is missing from this instance.
Please add it via the settings page on laminhub.

I had considered from None instead of from e but thought that maybe the additional context helps. Feedback is welcome.

@Zethson Zethson changed the title Better error message if wetlab is not added to the current instance ✨ Better error message if wetlab is not added to the current instance Jan 16, 2025
@Zethson
Copy link
Member Author

Zethson commented Jan 16, 2025

@Koncopd is there a way we can implement this more generally in _check_instance_setup or somewhere else so that I don't have to copy and paste this across all schemas modules?

Copy link

@github-actions github-actions bot temporarily deployed to pull request January 16, 2025 15:47 Inactive
@Koncopd
Copy link
Member

Koncopd commented Jan 16, 2025

Let me think about it a bit. Maybe we can do the check in _check_instance_setup indeed.

@Koncopd
Copy link
Member

Koncopd commented Jan 16, 2025

Working on this here laminlabs/lamindb-setup#946

@falexwolf
Copy link
Member

Ahhh, this is nice! It'd capture one of the key Django errors of death. 😄

And yes, this gotta be added on the lamindb-setup level.

@Zethson
Copy link
Member Author

Zethson commented Jan 17, 2025

Closing in favor of the lamindb-setup solution

@Zethson Zethson closed this Jan 17, 2025
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.

3 participants