tethysplatform / tethys

The Tethys Platform main Django website project repository.
http://tethysplatform.org/
BSD 2-Clause "Simplified" License
91 stars 50 forks source link

[BUG] Trailing slash not being appended automatically with /apps #1061

Open swainn opened 4 weeks ago

swainn commented 4 weeks ago

Describe the bug

Opening this url (from a key concepts tutorial) http://127.0.0.1:8000/apps results in an error. However, adding a slash ("/") to the end of the URL works.

To Reproduce Steps to reproduce the behavior:

  1. Install latest Tethys from main branch
  2. Start Tethys with tethys manage start
  3. Open http://127.0.0.1:8000/apps (no trailing slash)
  4. See error

Expected behavior /apps should automatically redirect to /apps/ to prevent this issue.

Errors/Traceback

``` Environment: Request Method: GET Request URL: http://127.0.0.1:8000/apps Django Version: 5.0.6 Python Version: 3.12.3 Installed Applications: ('channels', 'django.contrib.admin', 'django.contrib.auth', 'django.contrib.contenttypes', 'django.contrib.sessions', 'django.contrib.messages', 'django.contrib.staticfiles', 'django_bootstrap5', 'tethys_apps', 'tethys_compute', 'tethys_config', 'tethys_gizmos', 'tethys_layouts', 'tethys_sdk', 'tethys_services', 'tethys_quotas', 'guardian') Installed Middleware: ('django.contrib.sessions.middleware.SessionMiddleware', 'django.middleware.common.CommonMiddleware', 'django.middleware.csrf.CsrfViewMiddleware', 'django.contrib.auth.middleware.AuthenticationMiddleware', 'django.contrib.messages.middleware.MessageMiddleware', 'tethys_portal.middleware.TethysMfaRequiredMiddleware', 'django.middleware.clickjacking.XFrameOptionsMiddleware', 'tethys_portal.middleware.TethysAppAccessMiddleware') Traceback (most recent call last): File "/home/firehawk/miniconda3/envs/mtethys/lib/python3.12/site-packages/django/core/handlers/exception.py", line 55, in inner response = get_response(request) ^^^^^^^^^^^^^^^^^^^^^ File "/home/firehawk/Codes/tethys/tethys_portal/middleware.py", line 81, in __call__ app = get_active_app(request) ^^^^^^^^^^^^^^^^^^^^^^^ File "/home/firehawk/Codes/tethys/tethys_apps/utilities.py", line 151, in get_active_app app_root_url = url_parts[app_root_url_index] ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ Exception Type: IndexError at /apps Exception Value: list index out of range ```

Tethys Environment Information Include output from these commands:

4.2.0.post3.dev38+g59a80e44.d20240620

``` 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 ```
``` # 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 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 ```