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

[BUG] Warning during tethys manage start when using Django 5.0 #1060

Open
swainn opened this issue Jun 20, 2024 · 1 comment
Open

[BUG] Warning during tethys manage start when using Django 5.0 #1060

swainn opened this issue Jun 20, 2024 · 1 comment
Assignees
Labels
Milestone

Comments

@swainn
Copy link
Member

swainn commented Jun 20, 2024

Describe the bug

I see the following warning when starting the development server with tethys manage start with Django 5:

RuntimeWarning: Accessing the database during app initialization is discouraged. To fix this warning, avoid executing queries in AppConfig.ready() or when your app modules are imported.

This probably has to do with the app harvesting routines that get called on startup. It doesn't seem to be causing actual issues though, so I recommend we suppress the warning somehow.

To Reproduce

  1. Install latest dev version of Tethys with Django 5
  2. Run tethys manage start

Expected behavior

No ugly warnings.

Errors/Traceback

Loading Tethys Extensions...
Loading Tethys Apps...
/home/firehawk/miniconda3/envs/mtethys/lib/python3.12/site-packages/django/db/backends/utils.py:98: RuntimeWarning: Accessing the database during app initialization is discouraged. To fix this warning, avoid executing queries in AppConfig.ready() or when your app modules are imported.
  warnings.warn(self.APPS_NOT_READY_WARNING_MSG, category=RuntimeWarning)
Tethys Apps Loaded: dam_inventory

Performing system checks...

System check identified no issues (0 silenced).
June 20, 2024 - 03:31:49
Django version 5.0.6, using settings 'tethys_portal.settings'
Starting development server at http://127.0.0.1:8000/
Quit the server with CONTROL-C.

Screenshots
N/A

Tethys Environment Information
Include output from these commands:

  • tethys version

4.2.0.post3.dev38+g59a80e44.d20240620

  • conda info
active environment : mtethys
    active env location : /home/firehawk/miniconda3/envs/mtethys
            shell level : 2
       user config file : /home/firehawk/.condarc
 populated config files : 
          conda version : 24.5.0
    conda-build version : not installed
         python version : 3.12.3.final.0
                 solver : libmamba (default)
       virtual packages : __archspec=1=broadwell
                          __conda=24.5.0=0
                          __glibc=2.35=0
                          __linux=6.5.0=0
                          __unix=0=0
       base environment : /home/firehawk/miniconda3  (writable)
      conda av data dir : /home/firehawk/miniconda3/etc/conda
  conda av metadata url : None
           channel URLs : https://repo.anaconda.com/pkgs/main/linux-64
                          https://repo.anaconda.com/pkgs/main/noarch
                          https://repo.anaconda.com/pkgs/r/linux-64
                          https://repo.anaconda.com/pkgs/r/noarch
          package cache : /home/firehawk/miniconda3/pkgs
                          /home/firehawk/.conda/pkgs
       envs directories : /home/firehawk/miniconda3/envs
                          /home/firehawk/.conda/envs
               platform : linux-64
             user-agent : conda/24.5.0 requests/2.31.0 CPython/3.12.3 Linux/6.5.0-35-generic linuxmint/21.3 glibc/2.35 solver/libmamba conda-libmamba-solver/24.1.0 libmambapy/1.5.8 aau/0.4.4 c/. s/. e/.
                UID:GID : 1000:1000
             netrc file : None
           offline mode : False
  • conda list
# packages in environment at /home/firehawk/miniconda3/envs/mtethys:
#
# Name                    Version                   Build  Channel
_libgcc_mutex             0.1                 conda_forge    conda-forge
_openmp_mutex             4.5                       2_gnu    conda-forge
appdirs                   1.4.4              pyh9f0ad1d_0    conda-forge
asgiref                   3.8.1              pyhd8ed1ab_0    conda-forge
attrs                     23.2.0             pyh71513ae_0    conda-forge
autobahn                  23.6.2             pyhd8ed1ab_0    conda-forge
automat                   22.10.0            pyhd8ed1ab_0    conda-forge
bcrypt                    4.1.3           py312h4413252_0    conda-forge
brotli-python             1.1.0           py312h30efb56_1    conda-forge
bzip2                     1.0.8                hd590300_5    conda-forge
ca-certificates           2024.6.2             hbcca054_0    conda-forge
certifi                   2024.2.2           pyhd8ed1ab_0    conda-forge
cffi                      1.16.0          py312hf06ca03_0    conda-forge
channels                  4.0.0              pyhd8ed1ab_0    conda-forge
charset-normalizer        3.3.2              pyhd8ed1ab_0    conda-forge
constantly                15.1.0                     py_0    conda-forge
cryptography              42.0.8          py312hbcc2302_0    conda-forge
daphne                    3.0.2              pyhd8ed1ab_0    conda-forge
django                    5.0.6              pyhd8ed1ab_0    conda-forge
django-bootstrap5         24.2               pyhd8ed1ab_0    conda-forge
django-guardian           2.4.0              pyhd8ed1ab_0    conda-forge
django-model-utils        4.5.1              pyhd8ed1ab_0    conda-forge
hyperlink                 21.0.0             pyhd3deb0d_0    conda-forge
idna                      3.7                pyhd8ed1ab_0    conda-forge
incremental               22.10.0            pyhd8ed1ab_0    conda-forge
jinja2                    3.1.4              pyhd8ed1ab_0    conda-forge
ld_impl_linux-64          2.40                 hf3520f5_2    conda-forge
libexpat                  2.6.2                h59595ed_0    conda-forge
libffi                    3.4.2                h7f98852_5    conda-forge
libgcc-ng                 13.2.0               h77fa898_7    conda-forge
libgomp                   13.2.0               h77fa898_7    conda-forge
libnsl                    2.0.1                hd590300_0    conda-forge
libsqlite                 3.45.3               h2797004_0    conda-forge
libstdcxx-ng              13.2.0               hc0a3c3a_7    conda-forge
libuuid                   2.38.1               h0b41bf4_0    conda-forge
libxcrypt                 4.4.36               hd590300_1    conda-forge
libzlib                   1.3.1                h4ab18f5_1    conda-forge
markupsafe                2.1.5           py312h98912ed_0    conda-forge
ncurses                   6.5                  h59595ed_0    conda-forge
openssl                   3.3.1                h4ab18f5_0    conda-forge
packaging                 24.0               pyhd8ed1ab_0    conda-forge
pip                       24.0               pyhd8ed1ab_0    conda-forge
pyasn1                    0.6.0              pyhd8ed1ab_0    conda-forge
pyasn1-modules            0.4.0              pyhd8ed1ab_0    conda-forge
pycparser                 2.22               pyhd8ed1ab_0    conda-forge
pyopenssl                 24.0.0             pyhd8ed1ab_0    conda-forge
pysocks                   1.7.1              pyha2e5f31_6    conda-forge
python                    3.12.3          hab00c5b_0_cpython    conda-forge
python_abi                3.12                    4_cp312    conda-forge
pyyaml                    6.0.1           py312h98912ed_1    conda-forge
readline                  8.2                  h8228510_1    conda-forge
requests                  2.32.3             pyhd8ed1ab_0    conda-forge
service-identity          21.1.0             pyhd8ed1ab_0    conda-forge
service_identity          21.1.0               hd8ed1ab_0    conda-forge
setuptools                70.0.0             pyhd8ed1ab_0    conda-forge
setuptools-scm            8.1.0              pyhd8ed1ab_0    conda-forge
setuptools_scm            8.1.0                hd8ed1ab_0    conda-forge
six                       1.16.0             pyh6c4a22f_0    conda-forge
sqlparse                  0.5.0              pyhd8ed1ab_0    conda-forge
tethys-platform           4.2.0.post3.dev38+g59a80e44.d20240620          pypi_0    pypi
tethysapp-dam-inventory   0.0.1                     dev_0    <develop>
tk                        8.6.13          noxft_h4845f30_101    conda-forge
tomli                     2.0.1              pyhd8ed1ab_0    conda-forge
twisted                   24.3.0          py312h98912ed_0    conda-forge
txaio                     23.1.1             pyhd8ed1ab_0    conda-forge
typing-extensions         4.12.2               hd8ed1ab_0    conda-forge
typing_extensions         4.12.2             pyha770c72_0    conda-forge
tzdata                    2024a                h0c530f3_0    conda-forge
urllib3                   2.2.1              pyhd8ed1ab_0    conda-forge
wheel                     0.43.0             pyhd8ed1ab_1    conda-forge
xz                        5.2.6                h166bdaf_0    conda-forge
yaml                      0.2.5                h7f98852_2    conda-forge
zope.interface            6.4.post2       py312h9a8786e_0    conda-forge
@swainn swainn added the bug label Jun 20, 2024
@swainn swainn added this to the Version 4.3 milestone Jun 20, 2024
@swainn swainn self-assigned this Jun 20, 2024
@swainn
Copy link
Member Author

swainn commented Aug 26, 2024

This is being caused by the code that generates the permissions and groups fields for each app in the custom group field. The "fix" is probably to pull the parts of this that access the database out into lazy() calls so the database isn't queried until the form is loaded. Instead of querying the database to get the list of all apps, get the harvester singleton and get the list of apps from that. Then create the necessary fields for each app and add them to the GOP form, but use lazy() for the queryset value of these fields and call functions that query to build the options.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants