Is this a bug? KeyError: 'is_popup' on mysite/admin, while logging level = DEBUG. Django 1.10.6.
Hello, I am a django newbie, just making my first django site. I tried to log the errors of my site, and found out KeyError: 'is_popup' ... when accessing http://127.0.0.1:8000/admin/. I tried this also on fresh install, django 1.10.6, using python 3.5.2. I had nothing else installed in the virtual environment, and the only lines I wrote to reproduce the error was to add LOGGING = { 'version': 1, 'disable_existing_loggers': False, 'handlers': { 'file': { 'level': 'DEBUG', 'class': 'logging.FileHandler', 'filename': r'C:\Tmp\testproject\log.txt', }, }, 'loggers': { 'django': { 'handlers': ['file'], 'level': 'DEBUG', 'propagate': True, }, }, } to the bottom of the settings.py. Then, on server startup (at http://127.0.0.1:8000) I got (0.000) SELECT name, type FROM sqlite_master WHERE type in ('table', 'view') AND NOT name='sqlite_sequence' ORDER BY name; args=None (0.000) SELECT "django_migrations"."app", "django_migrations"."name" FROM "django_migrations"; args=() and on first refresh of the page "GET / HTTP/1.1" 200 1767 But, when accesing http://127.0.0.1:8000/admin/ I got (0.001) SELECT "django_session"."session_key", "django_session"."session_data", "django_session"."expire_date" FROM "django_session" WHERE ("django_session"."session_key" = 'ml9pjc4565zd009anzpufwpczy39fmpx' AND "django_session"."expire_date" > '2017-03-10 20:28:51.037208'); args=('ml9pjc4565zd009anzpufwpczy39fmpx', '2017-03-10 20:28:51.037208') (0.000) SELECT "auth_user"."id", "auth_user"."password", "auth_user"."last_login", "auth_user"."is_superuser", "auth_user"."username", "auth_user"."first_name", "auth_user"."last_name", "auth_user"."email", "auth_user"."is_staff", "auth_user"."is_active", "auth_user"."date_joined" FROM "auth_user" WHERE "auth_user"."id" = 1; args=(1,) Exception while resolving variable 'is_popup' in template 'admin/index.html'. Traceback (most recent call last): File "C:\Python\Test\lib\site-packages\django\template\base.py", line 885, in _resolve_lookup current = current[bit] File "C:\Python\Test\lib\site-packages\django\template\context.py", line 75, in __getitem__ raise KeyError(key) KeyError: 'is_popup' During handling of the above exception, another exception occurred: Traceback (most recent call last): File "C:\Python\Test\lib\site-packages\django\template\base.py", line 891, in _resolve_lookup if isinstance(current, BaseContext) and getattr(type(current), bit): AttributeError: type object 'RequestContext' has no attribute 'is_popup' During handling of the above exception, another exception occurred: Traceback (most recent call last): File "C:\Python\Test\lib\site-packages\django\template\base.py", line 900, in _resolve_lookup current = current[int(bit)] ValueError: invalid literal for int() with base 10: 'is_popup' During handling of the above exception, another exception occurred: Traceback (most recent call last): File "C:\Python\Test\lib\site-packages\django\template\base.py", line 907, in _resolve_lookup (bit, current)) # missing attribute django.template.base.VariableDoesNotExist: Failed lookup for key [is_popup] in "[{'None': None, 'False': False, 'True': True}, {'perms': , 'DEFAULT_MESSAGE_LEVELS': {'DEBUG': 10, 'INFO': 20, 'WARNING': 30, 'SUCCESS': 25, 'ERROR': 40}, 'csrf_token': ._get_val at 0x024B1D6148C8>>, 'request': , 'messages': , 'user': >}, {}, {'LANGUAGE_CODE': 'en-us', 'LANGUAGE_BIDI': False, 'title': .__proxy__ object at 0x024B1CB2F240>, 'has_permission': True, 'app_list': [{'models': [{'perms': {'add': True, 'delete': True, 'change': True}, 'admin_url': '/admin/auth/group/', 'add_url': '/admin/auth/group/add/', 'name': .__proxy__ object at 0x024B1D66D860>, 'object_name': 'Group'}, {'perms': {'add': True, 'delete': True, 'change': True}, 'admin_url': '/admin/auth/user/', 'add_url': '/admin/auth/user/add/', 'name': .__proxy__ object at 0x024B1D5AC710>, 'object_name': 'User'}], 'app_url': '/admin/auth/', 'name': .__proxy__ object at 0x024B1CB2FCF8>, 'has_module_perms': True, 'app_label': 'auth'}], 'site_title': .__proxy__ object at 0x024B1CB1BF28>, 'available_apps': [{'models': [{'perms': {'add': True, 'delete': True, 'change': True}, 'admin_url': '/admin/auth/group/', 'add_url': '/admin/auth/group/add/', 'name': .__proxy__ object at 0x024B1D66D470>, 'object_name': 'Group'}, {'perms': {'add': True, 'delete': True, 'change': True}, 'admin_url': '/admin/auth/user/', 'add_url': '/admin/auth/user/add/', 'name': .__proxy__ object at 0x024B1D66D048>, 'object_name': 'User'}], 'app_url': '/admin/auth/', 'name': .__proxy__ object at 0x024B1CB2FCF8>, 'has_module_perms': True, 'app_label': 'auth'}], 'site_header': .__proxy__ object at 0x024B1CB1BFD0>, 'site_url': '/'}]" Exception while resolving variable 'is_popup' in template 'admin/index.html'. Traceback (most recent call last): File "C:\Python\Test\lib\site-packages\
Re: Is this a bug? KeyError: 'is_popup' on mysite/admin, while logging level = DEBUG. Django 1.10.6.
Hi Daniel, Thank you for your anwer. I tested the option for using level: INFO for the django.template -logger. Your solution will suppress the Exception while resolving variable 'is_popup' in template 'admin/index.html' . ... being caught. However, I do not understand why should I just *suppress *Exceptions/KeyErrors in the templates? I did not understand *why* this exception is raised. If there is no such variable as 'is_popup', shoudn't I just provide one? Forgive me for asking if the answer is too trivial. I opened the 'admin/index.html' which extends 'base_site.html', which extends 'base.html', which has following lines (from the beginning of the file): {% load i18n static %} {% get_current_language as LANGUAGE_CODE %}{% get_current_language_bidi as LANGUAGE_BIDI %} {% block title %}{% endblock %} {% block extrastyle %}{% endblock %} {% if LANGUAGE_BIDI %}{% endif %} {% block extrahead %}{% endblock %} {% block blockbots %}{% endblock %} {% load i18n %} {% if not is_popup %} {% block branding %}{% endblock %} as we can see, there are exactly two lines in the (index.html) base.html having 'is_popup'. Could you, or someone else please enlighten me a bit more. Is it possible to get rid of this Exception/KeyError, other than filtering out it from the log? - np On Saturday, 11 March 2017 15:10:21 UTC+2, Daniel Hepper wrote: > > Yes, this is normal behavior. What you are seeing is the log output for a > missing template variable. Django logs these in log level debug. See > https://docs.djangoproject.com/en/1.10/topics/logging/#django-template > > To get rid of these, you can configure the logger for the template system > to only log messages with loglevel INFO and higher. > > 'loggers': { > 'django': { > 'handlers': ['file'], > 'level': 'DEBUG', > 'propagate': True, > }, > 'django.template': { > 'handlers': ['file'], > 'level': 'INFO', > 'propagate': True, > }, > }, > > Hope that helps, > > Daniel > https://consideratecode.com > > On Friday, March 10, 2017 at 11:03:19 PM UTC+1, np wrote: >> >> Hello, >> >> I am a django newbie, just making my first django site. I tried to log >> the errors of my site, and found out >> KeyError: 'is_popup' ... >> when accessing http://127.0.0.1:8000/admin/. >> >> I tried this also on fresh install, django 1.10.6, using python 3.5.2. I >> had nothing else installed in the virtual environment, and the only lines I >> wrote to reproduce the error was to add >> >> LOGGING = { >> 'version': 1, >> 'disable_existing_loggers': False, >> 'handlers': { >> 'file': { >> 'level': 'DEBUG', >> 'class': 'logging.FileHandler', >> 'filename': r'C:\Tmp\testproject\log.txt', >> }, >> }, >> 'loggers': { >> 'django': { >> 'handlers': ['file'], >> 'level': 'DEBUG', >> 'propagate': True, >> }, >> }, >> } >> >> to the bottom of the settings.py. >> >> Then, on server startup (at http://127.0.0.1:8000) I got >> >> (0.000) >> SELECT name, type FROM sqlite_master >> WHERE type in ('table', 'view') AND NOT name='sqlite_sequence' >> ORDER BY name; args=None >> (0.000) SELECT "django_migrations"."app", "django_migrations"."name" FROM >> "django_migrations"; args=() >> >> >> and on first refresh of the page >> "GET / HTTP/1.1" 200 1767 >> >> But, when accesing http://127.0.0.1:8000/admin/ I got >> >> (0.001) SELECT "django_session"."session_key", >> "django_session"."session_data", "django_session"."expire_date" FROM >> "django_session" WHERE ("django_session"."session_key" = >> 'ml9pjc4565zd009anzpufwpczy39fmpx' AND "django_session"."expire_date" > >> '2017-03-10 20:28:51.037208'); args=('ml9pjc4565zd009anzpufwpczy39fmpx', >> '2017-03-10 20:28:51.037208') >> (0.000) SELECT "auth_user"."id", "auth_user"."password", >> "auth_user"."last_login", "auth_user"."is_superuser", >&g
Re: Is this a bug? KeyError: 'is_popup' on mysite/admin, while logging level = DEBUG. Django 1.10.6.
Hi Thanks for your help Melvyn and Daniel.I was not familiar with this pattern. Good to hear that there is nothing actually wrong with the code. - np On Saturday, 11 March 2017 19:03:54 UTC+2, Melvyn Sopacua wrote: > > On Saturday 11 March 2017 07:55:58 np wrote: > > > > > being caught. However, I do not understand why should I just *suppress > > > *Exceptions/KeyErrors in the templates? I did not understand *why* > > > this exception is raised. If there is no such variable as 'is_popup', > > > shoudn't I just provide one? Forgive me for asking if the answer is > > > too trivial. > > > > The admin reuses templates (and forms and views) for a popup window. It > does so for the "plus" and "edit" buttons for foreign relations. > > > > It is a common pattern to "define something is it applies" and it be > undefined if it doesn't. It's kind of a shortcut boolean that saves an > extra line in the code. > > Django template code tries to keep programming out of the template, so > undefined and false are for all intents and purposes identical in > comparisons. > > > > The exception is logged, so that one is still able to determine why code > fails that you think shouldn't fail. > > -- > > Melvyn Sopacua > -- You received this message because you are subscribed to the Google Groups "Django users" group. To unsubscribe from this group and stop receiving emails from it, send an email to django-users+unsubscr...@googlegroups.com. To post to this group, send email to django-users@googlegroups.com. Visit this group at https://groups.google.com/group/django-users. To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/7bf8ebc7-f166-491a-8a67-10f94e3f4a37%40googlegroups.com. For more options, visit https://groups.google.com/d/optout.
django-admin makemessages PermissionError [WindError 32] and OsError [Errno 22]
Hi, I am using custom fabric script to make .po-files for i18n. The problem is, "django-admin makemessages" keeps on crashing. It also leaves undeleted .html.py files. I can reproduce this error also by using plain "django-admin makemessages -l pt". I think this problem in Windows-specific. I am using 64-bit Windows 10, Django 1.11, Fabric3 1.13.1.post1, and Windows Powershell 5.1.14393.1198. Any help would be appreciated. Br, np *"Minimal working example":* - Crashed on third try. Sometimes it complains about "locale\django.pot" being used by another process, too. Fourth try worked fine. () PS C:\Users\\Dropbox\\site\src\\templates\bases> django-admin makemessages -l pt processing locale pt () PS C:\Users\\Dropbox\\site\src\\templates\bases> django-admin makemessages -l pt processing locale pt () PS C:\Users\\Dropbox\\site\src\\templates\bases> django-admin makemessages -l pt Traceback (most recent call last): File "C:\Users\\Miniconda3\Lib\runpy.py", line 184, in _run_module_as_main "__main__", mod_spec) File "C:\Users\\Miniconda3\Lib\runpy.py", line 85, in _run_code exec(code, run_globals) File "C:\Python\VirtualEnv\\Scripts\django-admin.exe\__main__.py", line 9, in File "c:\python\virtualenv\\lib\site-packages\django\core\management\__init__.py", line 363, in execute_from_command_line utility.execute() File "c:\python\virtualenv\\lib\site-packages\django\core\management\__init__.py", line 355, in execute self.fetch_command(subcommand).run_from_argv(self.argv) File "c:\python\virtualenv\\lib\site-packages\django\core\management\base.py", line 283, in run_from_argv self.execute(*args, **cmd_options) File "c:\python\virtualenv\\lib\site-packages\django\core\management\base.py", line 330, in execute output = self.handle(*args, **options) File "c:\python\virtualenv\\lib\site-packages\django\core\management\commands\makemessages.py", line 360, in handle potfiles = self.build_potfiles() File "c:\python\virtualenv\\lib\site-packages\django\core\management\commands\makemessages.py", line 402, in build_potfiles self.process_files(file_list) File "c:\python\virtualenv\\lib\site-packages\django\core\management\commands\makemessages.py", line 499, in process_files self.process_locale_dir(locale_dir, files) File "c:\python\virtualenv\\lib\site-packages\django\core\management\commands\makemessages.py", line 594, in process_locale_dir build_file.cleanup() File "c:\python\virtualenv\\lib\site-packages\django\core\management\commands\makemessages.py", line 157, in cleanup os.unlink(self.work_path) PermissionError: [WinError 32] The process cannot access the file because it is being used by another process: '.\\base.html.py' () PS C:\Users\\Dropbox\\site\src\\templates\bases> *Real-usage example* *Fabric code:* def translate(appfolder=None): """ Use django-admin makemessages to make .po files INPUTS: folder: pathlib.Path object for the folder where to start. Used for recursion. (in normal usage, no 'folder' parameter is provided.) """ forbidden = ('__pycache__', 'migrations', 'locale', 'utils', 'static') if not appfolder: appfolder = Path(__file__).parent.parent / '' for item in appfolder.iterdir(): if item.is_dir() and (item.name not in forbidden): if not (item / 'locale').exists(): (item / 'locale').mkdir() print('Created {}'.format(str((item / 'locale' print('Running makemessages in {}'.format(str(item))) os.chdir(str(item)) os.system("python {django_admin} makemessages -l fi".format( django_admin = django_admin )) translate(appfolder=item) *Traceback:* - Some files before and after these errors did not produce any errors. Running makemessages in C:\Users\\Dropbox\\site\src\\templates Traceback (most recent call last): File "C:\Python\VirtualEnv\\Scripts\django-admin.py", line 5, in management.execute_from_command_line() File "C:\Python\VirtualEnv\\lib\site-packages\django\core\management\__init__.py", line 363, in execute_from_command_line utility.execute() File "C:\Python\VirtualEnv\\lib\site-packages\django\core\management\__init__.py", line 355, in execute self.fetch_command(subcommand).run_from_argv(self.argv) File "C:\Python\VirtualEnv\\lib\site-packages\django\core\management\base.py", line 283, in run_from_argv self.execute(*args, **cmd_options) File &q