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

'fieldsets' and 'subtitle' missing from Template context #586

Open
spiceworm opened this issue Sep 14, 2024 · 2 comments
Open

'fieldsets' and 'subtitle' missing from Template context #586

spiceworm opened this issue Sep 14, 2024 · 2 comments

Comments

@spiceworm
Copy link

spiceworm commented Sep 14, 2024

Describe the problem

'fieldsets' and 'subtitle' are missing from template context which results in VariableDoesNotExist exceptions. fieldsets will only be missing if settings.CONFIG_FIELDSETS is falsy. I verified this is the problem by adding title=None, fieldsets=[] to context and it stop the exceptions from being thrown.

Steps to reproduce

Run django app with log level set to DEBUG and navigate to /admin/constance/config/

DEBUG 2024-09-14 02:57:31,496 base 471 128195625114496 Exception while resolving variable 'subtitle' in template 'admin/constance/change_list.html'.        
Traceback (most recent call last):
  File "/usr/local/lib/python3.12/site-packages/django/template/base.py", line 883, in _resolve_lookup
    current = current[bit]
              ~~~~~~~^^^^^
  File "/usr/local/lib/python3.12/site-packages/django/template/context.py", line 85, in __getitem__
    raise KeyError(key)
KeyError: 'subtitle'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/usr/local/lib/python3.12/site-packages/django/template/base.py", line 889, in _resolve_lookup
    if isinstance(current, BaseContext) and getattr(
                                            ^^^^^^^^
AttributeError: type object 'RequestContext' has no attribute 'subtitle'
[2024-09-14 02:58:37 +0000] [500] [DEBUG] GET /admin/constance/config/                                                                                                                  
DEBUG 2024-09-14 02:58:37,761 base 500 140439392750464 Exception while resolving variable 'fieldsets' in template 'admin/constance/change_list.html'.
Traceback (most recent call last):
  File "/usr/local/lib/python3.12/site-packages/django/template/base.py", line 883, in _resolve_lookup
    current = current[bit]
              ~~~~~~~^^^^^
  File "/usr/local/lib/python3.12/site-packages/django/template/context.py", line 85, in __getitem__
    raise KeyError(key)
KeyError: 'fieldsets'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/usr/local/lib/python3.12/site-packages/django/template/base.py", line 889, in _resolve_lookup
    if isinstance(current, BaseContext) and getattr(
                                            ^^^^^^^^
AttributeError: type object 'RequestContext' has no attribute 'fieldsets'

System configuration

  • Django version: 5.1.1
  • Python version: 3.12.6
  • Django-Constance version: 4.1.1
@Mogost
Copy link
Member

Mogost commented Sep 16, 2024

@spiceworm Do you use string_if_invalid? I believe it's why you are getting this exception.
I'd recommend you not to use it. More details you can get in Adam's blogpost https://adamj.eu/tech/2022/03/30/how-to-make-django-error-for-undefined-template-variables/#with-the-string-if-invalid-option

@spiceworm
Copy link
Author

I am not using string_if_invalid. See example in #587 (comment)

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 a pull request may close this issue.

2 participants