Opened 3 years ago

Closed 3 years ago

#33580 closed Bug (fixed)

Initialization of Django fails when emulated in Wine

Reported by: Jochem Franken Owned by: Jochem Franken
Component: Core (Management commands) Version: 3.2
Severity: Normal Keywords: wine, color
Cc: Triage Stage: Ready for checkin
Has patch: yes Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

Description

From version 3.2 and onwards, when running management commands, the registry is searched for the key 'Console'. In emulated environments (via Wine) this fails as the key is nonexistent.

Traceback (most recent call last):
  File "C:\python38\lib\site-packages\django\core\management\__init__.py", line 375, in execute
    autoreload.check_errors(django.setup)()
  File "C:\python38\lib\site-packages\django\utils\autoreload.py", line 64, in wrapper
    fn(*args, **kwargs)
  File "C:\python38\lib\site-packages\django\__init__.py", line 19, in setup
    configure_logging(settings.LOGGING_CONFIG, settings.LOGGING)
  File "C:\python38\lib\site-packages\django\utils\log.py", line 71, in configure_logging
    logging.config.dictConfig(DEFAULT_LOGGING)
  File "C:\python38\lib\logging\config.py", line 808, in dictConfig
    dictConfigClass(config).configure()
  File "C:\python38\lib\logging\config.py", line 545, in configure
    raise ValueError('Unable to configure '
ValueError: Unable to configure formatter 'django.server'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "manage.py", line 22, in <module>
    main()
  File "manage.py", line 18, in main
    execute_from_command_line(sys.argv)
  File "C:\python38\lib\site-packages\django\core\management\__init__.py", line 419, in execute_from_command_line
    utility.execute()
  File "C:\python38\lib\site-packages\django\core\management\__init__.py", line 388, in execute
    _parser = self.fetch_command('runserver').create_parser('django', 'runserver')
  File "C:\python38\lib\site-packages\django\core\management\__init__.py", line 257, in fetch_command
    klass = load_command_class(app_name, subcommand)
  File "C:\python38\lib\site-packages\django\core\management\__init__.py", line 40, in load_command_class
    return module.Command()
  File "C:\python38\lib\site-packages\django\core\management\base.py", line 251, in __init__
    self.style = color_style(force_color)
  File "C:\python38\lib\site-packages\django\core\management\color.py", line 105, in color_style
    if not force_color and not supports_color():
  File "C:\python38\lib\site-packages\django\core\management\color.py", line 55, in supports_color
    vt_codes_enabled_in_windows_registry()
  File "C:\python38\lib\site-packages\django\core\management\color.py", line 36, in vt_codes_enabled_in_windows_registry
    reg_key = winreg.OpenKey(winreg.HKEY_CURRENT_USER, 'Console')
FileNotFoundError: [WinError 2] File not found

The code block where the error happens is:

def vt_codes_enabled_in_windows_registry():
        """
        Check the Windows Registry to see if VT code handling has been enabled
        by default, see https://superuser.com/a/1300251/447564.
        """
        try:
            # winreg is only available on Windows.
            import winreg
        except ImportError:
            return False
        else:
            reg_key = winreg.OpenKey(winreg.HKEY_CURRENT_USER, "Console") # ERROR
            try:
                reg_key_value, _ = winreg.QueryValueEx(reg_key, "VirtualTerminalLevel")
            except FileNotFoundError:
                return False
            else:
                return reg_key_value == 1

Moving the indicated line into the try/except block fixes the error.

Change History (4)

comment:1 by Jochem Franken, 3 years ago

Owner: changed from nobody to Jochem Franken
Status: newassigned

comment:2 by Mariusz Felisiak, 3 years ago

Triage Stage: UnreviewedAccepted

I didn't reproduce this issue locally, but it looks valid.

comment:3 by Mariusz Felisiak, 3 years ago

Triage Stage: AcceptedReady for checkin

comment:4 by GitHub <noreply@…>, 3 years ago

Resolution: fixed
Status: assignedclosed

In 5f9ad172:

Fixed #33580 -- Fixed crash when checking support for terminal colors on Wine.

Regression in f1585c54d0242d71cdc63421f751528472b1c9c2.

Note: See TracTickets for help on using tickets.
Back to Top