tethysplatform / tethys

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

tethys_quotas.UserQuota' has no ForeignKey to 'tethys_apps.ProxyApp #777

Closed sdc50 closed 2 years ago

sdc50 commented 2 years ago

I have been occationally been getting this error. It seems like restarting the server resolves it, but I'm not sure why.

Environment: Request Method: GET Request URL: http://vtime.erdc.dren.mil/admin/tethys_apps/proxyapp/6/change/ Django Version: 2.2.14 Python Version: 3.7.12 Installed Applications: ('django.contrib.admin', 'django.contrib.auth', 'django.contrib.contenttypes', 'django.contrib.sessions', 'django.contrib.messages', 'django.contrib.staticfiles', 'django_gravatar', 'bootstrap3', 'termsandconditions', 'tethys_config', 'tethys_apps', 'tethys_gizmos', 'tethys_services', 'tethys_compute', 'tethys_quotas', 'social_django', 'guardian', 'session_security', 'captcha', 'snowpenguin.django.recaptcha2', 'rest_framework', 'rest_framework.authtoken', 'analytical', 'channels', 'mfa', 'axes') 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.TethysSocialAuthExceptionMiddleware', 'tethys_portal.middleware.TethysAppAccessMiddleware', 'session_security.middleware.SessionSecurityMiddleware', 'axes.middleware.AxesMiddleware') Traceback: File "./django/core/handlers/exception.py" in inner 34. response = get_response(request) File "./django/core/handlers/base.py" in _get_response 115. response = self.process_exception_by_middleware(e, request) File "./django/core/handlers/base.py" in _get_response 113. response = wrapped_callback(request, *callback_args, **callback_kwargs) File "./django/contrib/admin/options.py" in wrapper 606. return self.admin_site.admin_view(view)(*args, **kwargs) File "./django/utils/decorators.py" in _wrapped_view 142. response = view_func(request, *args, **kwargs) File "./django/views/decorators/cache.py" in _wrapped_view_func 44. response = view_func(request, *args, **kwargs) File "./django/contrib/admin/sites.py" in inner 223. return view(request, *args, **kwargs) File "./django/contrib/admin/options.py" in change_view 1648. return self.changeform_view(request, object_id, form_url, extra_context) File "./django/utils/decorators.py" in _wrapper 45. return bound_method(*args, **kwargs) File "./django/utils/decorators.py" in _wrapped_view 142. response = view_func(request, *args, **kwargs) File "./django/contrib/admin/options.py" in changeform_view 1529. return self._changeform_view(request, object_id, form_url, extra_context) File "./django/contrib/admin/options.py" in _changeform_view 1590. formsets, inline_instances = self._create_formsets(request, obj, change=True) File "./django/contrib/admin/options.py" in _create_formsets 1945. for FormSet, inline in self.get_formsets_with_inlines(*get_formsets_args): File "./django/contrib/admin/options.py" in get_formsets_with_inlines 794. yield inline.get_formset(request, obj), inline File "./django/contrib/admin/options.py" in get_formset 2131. return inlineformset_factory(self.parent_model, self.model, **defaults) File "./django/forms/models.py" in inlineformset_factory 1053. fk = _get_foreign_key(parent_model, model, fk_name=fk_name) File "./django/forms/models.py" in _get_foreign_key 1027. parent_model._meta.label, Exception Type: ValueError at /admin/tethys_apps/proxyapp/6/change/ Exception Value: 'tethys_quotas.UserQuota' has no ForeignKey to 'tethys_apps.ProxyApp'.
swainn commented 2 years ago

Exception Type: ValueError at /admin/tethys_apps/proxyapp/6/change/

It looks to me that this error occurs when visiting the admin page for the Proxy app? Is that true?

sdc50 commented 2 years ago

It looks to me that this error occurs when visiting the admin page for the Proxy app?

Yes that is True, although it doesn't always occur when visiting the admin page for a Proxy app, so I'm not sure what the exact scenario is that produces it. I was just able to produce it again with Tethys 4:

Environment: Request Method: GET Request URL: http://127.0.0.1:8000/admin/tethys_apps/proxyapp/1/change/ Django Version: 3.2.12 Python Version: 3.10.5 Installed Applications: ('channels', 'corsheaders', 'django.contrib.admin', 'django.contrib.auth', 'django.contrib.contenttypes', 'django.contrib.sessions', 'django.contrib.messages', 'django.contrib.staticfiles', 'django_gravatar', 'django_bootstrap5', 'termsandconditions', 'tethys_apps', 'tethys_compute', 'tethys_config', 'tethys_gizmos', 'tethys_layouts', 'tethys_sdk', 'tethys_services', 'tethys_quotas', 'social_django', 'guardian', 'session_security', 'captcha', 'snowpenguin.django.recaptcha2', 'rest_framework', 'rest_framework.authtoken', 'analytical', 'mfa', 'axes') Installed Middleware: ('django.contrib.sessions.middleware.SessionMiddleware', 'corsheaders.middleware.CorsMiddleware', '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.TethysSocialAuthExceptionMiddleware', 'tethys_portal.middleware.TethysAppAccessMiddleware', 'session_security.middleware.SessionSecurityMiddleware', 'axes.middleware.AxesMiddleware') Traceback (most recent call last): File "/Users/rditlsc9/miniconda/envs/tethys-dev/lib/python3.10/site-packages/asgiref/sync.py", line 472, in thread_handler raise exc_info[1] File "/Users/rditlsc9/miniconda/envs/tethys-dev/lib/python3.10/site-packages/django/core/handlers/exception.py", line 38, in inner response = await get_response(request) File "/Users/rditlsc9/miniconda/envs/tethys-dev/lib/python3.10/site-packages/django/core/handlers/base.py", line 233, in _get_response_async response = await wrapped_callback(request, *callback_args, **callback_kwargs) File "/Users/rditlsc9/miniconda/envs/tethys-dev/lib/python3.10/site-packages/asgiref/sync.py", line 435, in __call__ ret = await asyncio.wait_for(future, timeout=None) File "/Users/rditlsc9/miniconda/envs/tethys-dev/lib/python3.10/asyncio/tasks.py", line 408, in wait_for return await fut File "/Users/rditlsc9/miniconda/envs/tethys-dev/lib/python3.10/site-packages/asgiref/current_thread_executor.py", line 22, in run result = self.fn(*self.args, **self.kwargs) File "/Users/rditlsc9/miniconda/envs/tethys-dev/lib/python3.10/site-packages/asgiref/sync.py", line 476, in thread_handler return func(*args, **kwargs) File "/Users/rditlsc9/miniconda/envs/tethys-dev/lib/python3.10/site-packages/django/contrib/admin/options.py", line 616, in wrapper return self.admin_site.admin_view(view)(*args, **kwargs) File "/Users/rditlsc9/miniconda/envs/tethys-dev/lib/python3.10/site-packages/django/utils/decorators.py", line 130, in _wrapped_view response = view_func(request, *args, **kwargs) File "/Users/rditlsc9/miniconda/envs/tethys-dev/lib/python3.10/site-packages/django/views/decorators/cache.py", line 44, in _wrapped_view_func response = view_func(request, *args, **kwargs) File "/Users/rditlsc9/miniconda/envs/tethys-dev/lib/python3.10/site-packages/django/contrib/admin/sites.py", line 232, in inner return view(request, *args, **kwargs) File "/Users/rditlsc9/miniconda/envs/tethys-dev/lib/python3.10/site-packages/django/contrib/admin/options.py", line 1660, in change_view return self.changeform_view(request, object_id, form_url, extra_context) File "/Users/rditlsc9/miniconda/envs/tethys-dev/lib/python3.10/site-packages/django/utils/decorators.py", line 43, in _wrapper return bound_method(*args, **kwargs) File "/Users/rditlsc9/miniconda/envs/tethys-dev/lib/python3.10/site-packages/django/utils/decorators.py", line 130, in _wrapped_view response = view_func(request, *args, **kwargs) File "/Users/rditlsc9/miniconda/envs/tethys-dev/lib/python3.10/site-packages/django/contrib/admin/options.py", line 1540, in changeform_view return self._changeform_view(request, object_id, form_url, extra_context) File "/Users/rditlsc9/miniconda/envs/tethys-dev/lib/python3.10/site-packages/django/contrib/admin/options.py", line 1604, in _changeform_view formsets, inline_instances = self._create_formsets(request, obj, change=True) File "/Users/rditlsc9/miniconda/envs/tethys-dev/lib/python3.10/site-packages/django/contrib/admin/options.py", line 1961, in _create_formsets for FormSet, inline in self.get_formsets_with_inlines(*get_formsets_args): File "/Users/rditlsc9/miniconda/envs/tethys-dev/lib/python3.10/site-packages/django/contrib/admin/options.py", line 799, in get_formsets_with_inlines yield inline.get_formset(request, obj), inline File "/Users/rditlsc9/miniconda/envs/tethys-dev/lib/python3.10/site-packages/django/contrib/admin/options.py", line 2141, in get_formset return inlineformset_factory(self.parent_model, self.model, **defaults) File "/Users/rditlsc9/miniconda/envs/tethys-dev/lib/python3.10/site-packages/django/forms/models.py", line 1069, in inlineformset_factory fk = _get_foreign_key(parent_model, model, fk_name=fk_name) File "/Users/rditlsc9/miniconda/envs/tethys-dev/lib/python3.10/site-packages/django/forms/models.py", line 1038, in _get_foreign_key raise ValueError( Exception Type: ValueError at /admin/tethys_apps/proxyapp/1/change/ Exception Value: 'tethys_quotas.UserQuota' has no ForeignKey to 'tethys_apps.ProxyApp'.
sdc50 commented 2 years ago

It looks like it's not just the proxy app admin page. I just got a similar error on a job admin page:

Environment: Request Method: GET Request URL: http://127.0.0.1:8000/admin/tethys_compute/tethysjob/15/change/ Django Version: 3.2.12 Python Version: 3.10.5 Installed Applications: ('channels', 'corsheaders', 'django.contrib.admin', 'django.contrib.auth', 'django.contrib.contenttypes', 'django.contrib.sessions', 'django.contrib.messages', 'django.contrib.staticfiles', 'django_gravatar', 'django_bootstrap5', 'termsandconditions', 'tethys_apps', 'tethys_compute', 'tethys_config', 'tethys_gizmos', 'tethys_layouts', 'tethys_sdk', 'tethys_services', 'tethys_quotas', 'social_django', 'guardian', 'session_security', 'captcha', 'snowpenguin.django.recaptcha2', 'rest_framework', 'rest_framework.authtoken', 'analytical', 'mfa', 'axes') Installed Middleware: ('django.contrib.sessions.middleware.SessionMiddleware', 'corsheaders.middleware.CorsMiddleware', '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.TethysSocialAuthExceptionMiddleware', 'tethys_portal.middleware.TethysAppAccessMiddleware', 'session_security.middleware.SessionSecurityMiddleware', 'axes.middleware.AxesMiddleware') Traceback (most recent call last): File "/Users/rditlsc9/miniconda/envs/tethys-dev/lib/python3.10/site-packages/asgiref/sync.py", line 472, in thread_handler raise exc_info[1] File "/Users/rditlsc9/miniconda/envs/tethys-dev/lib/python3.10/site-packages/django/core/handlers/exception.py", line 38, in inner response = await get_response(request) File "/Users/rditlsc9/miniconda/envs/tethys-dev/lib/python3.10/site-packages/django/core/handlers/base.py", line 233, in _get_response_async response = await wrapped_callback(request, *callback_args, **callback_kwargs) File "/Users/rditlsc9/miniconda/envs/tethys-dev/lib/python3.10/site-packages/asgiref/sync.py", line 435, in __call__ ret = await asyncio.wait_for(future, timeout=None) File "/Users/rditlsc9/miniconda/envs/tethys-dev/lib/python3.10/asyncio/tasks.py", line 408, in wait_for return await fut File "/Users/rditlsc9/miniconda/envs/tethys-dev/lib/python3.10/site-packages/asgiref/current_thread_executor.py", line 22, in run result = self.fn(*self.args, **self.kwargs) File "/Users/rditlsc9/miniconda/envs/tethys-dev/lib/python3.10/site-packages/asgiref/sync.py", line 476, in thread_handler return func(*args, **kwargs) File "/Users/rditlsc9/miniconda/envs/tethys-dev/lib/python3.10/site-packages/django/contrib/admin/options.py", line 616, in wrapper return self.admin_site.admin_view(view)(*args, **kwargs) File "/Users/rditlsc9/miniconda/envs/tethys-dev/lib/python3.10/site-packages/django/utils/decorators.py", line 130, in _wrapped_view response = view_func(request, *args, **kwargs) File "/Users/rditlsc9/miniconda/envs/tethys-dev/lib/python3.10/site-packages/django/views/decorators/cache.py", line 44, in _wrapped_view_func response = view_func(request, *args, **kwargs) File "/Users/rditlsc9/miniconda/envs/tethys-dev/lib/python3.10/site-packages/django/contrib/admin/sites.py", line 232, in inner return view(request, *args, **kwargs) File "/Users/rditlsc9/miniconda/envs/tethys-dev/lib/python3.10/site-packages/django/contrib/admin/options.py", line 1660, in change_view return self.changeform_view(request, object_id, form_url, extra_context) File "/Users/rditlsc9/miniconda/envs/tethys-dev/lib/python3.10/site-packages/django/utils/decorators.py", line 43, in _wrapper return bound_method(*args, **kwargs) File "/Users/rditlsc9/miniconda/envs/tethys-dev/lib/python3.10/site-packages/django/utils/decorators.py", line 130, in _wrapped_view response = view_func(request, *args, **kwargs) File "/Users/rditlsc9/miniconda/envs/tethys-dev/lib/python3.10/site-packages/django/contrib/admin/options.py", line 1540, in changeform_view return self._changeform_view(request, object_id, form_url, extra_context) File "/Users/rditlsc9/miniconda/envs/tethys-dev/lib/python3.10/site-packages/django/contrib/admin/options.py", line 1604, in _changeform_view formsets, inline_instances = self._create_formsets(request, obj, change=True) File "/Users/rditlsc9/miniconda/envs/tethys-dev/lib/python3.10/site-packages/django/contrib/admin/options.py", line 1961, in _create_formsets for FormSet, inline in self.get_formsets_with_inlines(*get_formsets_args): File "/Users/rditlsc9/miniconda/envs/tethys-dev/lib/python3.10/site-packages/django/contrib/admin/options.py", line 799, in get_formsets_with_inlines yield inline.get_formset(request, obj), inline File "/Users/rditlsc9/miniconda/envs/tethys-dev/lib/python3.10/site-packages/django/contrib/admin/options.py", line 2141, in get_formset return inlineformset_factory(self.parent_model, self.model, **defaults) File "/Users/rditlsc9/miniconda/envs/tethys-dev/lib/python3.10/site-packages/django/forms/models.py", line 1069, in inlineformset_factory fk = _get_foreign_key(parent_model, model, fk_name=fk_name) File "/Users/rditlsc9/miniconda/envs/tethys-dev/lib/python3.10/site-packages/django/forms/models.py", line 1038, in _get_foreign_key raise ValueError( Exception Type: ValueError at /admin/tethys_compute/tethysjob/15/change/ Exception Value: 'tethys_quotas.UserQuota' has no ForeignKey to 'tethys_compute.TethysJob'.
sdc50 commented 2 years ago

I also think I understand how to reproduce the error. It seems to happen only after creating a new user and before the server is restarted.

Clarification: it happens when a new user is created via the admin portal. It doesn't seem to happen when a new user signs up via the interface.

swainn commented 2 years ago

More Clarification: The error occurs after visiting a user admin page (that renders the custom quotas field).

swainn commented 2 years ago

This is not true of all of the pages that the error occurs on, but the admin form for a Tethys Job has a "User field" with edit and add buttons. Or maybe more generally, the model has a relationship with Users?

image

swainn commented 2 years ago

The error occurs on these pages (not exhaustive):

- Users MFA Keys > [user] - `ValueError at /admin/mfa/user_keys/8/change/ 'tethys_quotas.UserQuota' has no ForeignKey to 'mfa.User_Keys'.` - Tokens > [token] - `ValueError at /admin/authtoken/tokenproxy/5/change/ 'tethys_quotas.UserQuota' has no ForeignKey to 'authtoken.TokenProxy'.` - Groups > [group] - `ValueError at /admin/auth/group/7/change/ 'tethys_quotas.UserQuota' has no ForeignKey to 'auth.Group'.` - Proxy Apps > [add] - `ValueError at /admin/tethys_apps/proxyapp/add/ 'tethys_quotas.UserQuota' has no ForeignKey to 'tethys_apps.ProxyApp'.` - Dask Schedulers > [scheduler] - `ValueError at /admin/tethys_compute/daskscheduler/1/change/ 'tethys_quotas.UserQuota' has no ForeignKey to 'tethys_compute.DaskScheduler'.` - HTCondor Schedulers > [add] - `ValueError at /admin/tethys_compute/condorscheduler/add/ 'tethys_quotas.UserQuota' has no ForeignKey to 'tethys_compute.CondorScheduler'.` - Jobs > [job] - `ValueError at /admin/tethys_compute/tethysjob/63/change/ 'tethys_quotas.UserQuota' has no ForeignKey to 'tethys_compute.TethysJob'.` - Dataset Services > [service] - `ValueError at /admin/tethys_services/datasetservice/add/ 'tethys_quotas.UserQuota' has no ForeignKey to 'tethys_services.DatasetService'.` - Spatial Dataset Services > [service] - `ValueError at /admin/tethys_services/datasetservice/add/ 'tethys_quotas.UserQuota' has no ForeignKey to 'tethys_services.SpatialDatasetService'.` - Persistent Store Services > [service] - `ValueError at /admin/tethys_services/datasetservice/add/ 'tethys_quotas.UserQuota' has no ForeignKey to 'tethys_services.PersistentStoreService'.` - Web Processing Services > [add] - `ValueError at /admin/tethys_services/datasetservice/add/ 'tethys_quotas.UserQuota' has no ForeignKey to 'tethys_services.WebProcessingService'.`

TL;DR: It renders almost any page of the admin pages with models unusable.