I'm trying to get an existing Django 1.11.7 (Python 3.5) project up and running on my Windows 10 box. After getting my environment set up, I'm now seeing the home page after running the application, but any internal page I visit I get the following error:
argument 5: <class 'TypeError'>: expected LP_OVERLAPPED instance instead of pointer to OVERLAPPED
I have traced this to a call from compress.py (Django compressor) for some compressed CSS files, to some win32 file locking code in the internals of django.core, specifically this line: https://github.com/django/django/blob/master/django/core/files/locks.py#L86 (UnlockFileEx in the snip below).
class OVERLAPPED(Structure):
_anonymous_ = ['_offset_union']
_fields_ = [
('Internal', ULONG_PTR),
('InternalHigh', ULONG_PTR),
('_offset_union', _OFFSET_UNION),
('hEvent', HANDLE)]
LPOVERLAPPED = POINTER(OVERLAPPED)
....
def lock(f, flags):
hfile = msvcrt.get_osfhandle(_fd(f))
overlapped = OVERLAPPED()
ret = LockFileEx(hfile, flags, 0, 0, 0xFFFF0000, byref(overlapped))
return bool(ret)
def unlock(f):
hfile = msvcrt.get_osfhandle(_fd(f))
overlapped = OVERLAPPED()
ret = UnlockFileEx(hfile, 0, 0, 0xFFFF0000, byref(overlapped))
return bool(ret)
The strange thing is that both the LockFileEx and UnlockFileEx methods are called on the home page without error. Inspecting the locals in both the successful and unsuccessful calls turned up nothing.
Stack trace in case it helps (higher stack redacted):
File "C:\x\env\lib\site-packages\compressor\templatetags\compress.py", line 127, in render
return self.render_compressed(context, self.kind, self.mode, forced=forced)
File "C:\x\env\lib\site-packages\compressor\templatetags\compress.py", line 103, in render_compressed
rendered_output = compressor.output(mode, forced=forced)
File "C:\x\env\lib\site-packages\compressor\css.py", line 49, in output
ret.append(subnode.output(*args, **kwargs))
File "C:\x\env\lib\site-packages\compressor\css.py", line 51, in output
return super(CssCompressor, self).output(*args, **kwargs)
File "C:\x\env\lib\site-packages\compressor\base.py", line 292, in output
output = '\n'.join(self.filter_input(forced))
File "C:\x\env\lib\site-packages\compressor\base.py", line 232, in filter_input
for hunk in self.hunks(forced):
File "C:\x\env\lib\site-packages\compressor\base.py", line 215, in hunks
basename=basename)
File "C:\x\env\lib\site-packages\compressor\base.py", line 307, in handle_output
return output_func(mode, content, forced, basename)
File "C:\x\env\lib\site-packages\compressor\base.py", line 319, in output_file
self.storage.save(new_filepath, ContentFile(content.encode(self.charset)))
File "C:\x\env\lib\site-packages\django\core\files\storage.py", line 54, in save
return self._save(name, content)
File "C:\x\env\lib\site-packages\django\core\files\storage.py", line 357, in _save
locks.unlock(fd)
File "C:\x\env\lib\site-packages\django\core\files\locks.py", line 86, in unlock
ret = UnlockFileEx(hfile, 0, 0, 0xFFFF0000, byref(overlapped))
It appears the files that are working with the locking/unlocking are static CSS files. Both JS and LESS are the ones throwing the above exception. It appears that the project is using yuglify for both the CSS and JS filters, if that helps.
In my case, this was due to a conflict with the youtube-dl package having similarly-named classes, variables and methods as the django-compressor package. I was able to confirm this by "hacking" the names of the various tokens in both instances, resulting in an error argument 5: <class 'TypeError'>: expected LP_OVERLAPPED2 instance instead of pointer to OVERLAPPED3
I have removed the youtube-dl package from my environment for now as a temporary solution to getting this running in my local dev environment.