Skip to content

sterliakov/py3_10_wsgi_dataclasses_error

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

3 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Bug explanation

After upgrading to python3.10 code with dataclasses stopped working with mod_wsgi.

If a class is created with @dataclass decorator (with just a single attribute x: str) and then instantiated somewhere before creating application, an exception is thrown. The reason is missing generated __init__ method (I confirmed that everything works if I define __init__ manually). Unfortunately, in real project it's part of external library and dataclass is instantiated in imported module, so there's no way to define __init__ by hands. The code without changes (all packages have same versions too) works with python3.9.

The traceback is:

File "/var/www/html/proof/wsgi.py", line 9, in <module>
  Test('a')
TypeError: Test() takes no arguments

Steps to reproduce

  1. Run docker-compose up -d --build (or build independently and then run)
  2. Navigate to localhost:8000 in any browser or use curl http://localhost:8000/. Look at 500 Internal Server Error.
  3. Access apache logs (docker exec -it <container_id> cat /var/log/apache2/error.log) to see error message.
  4. Shut down docker, change FROM python:3.10-slim to FROM python:3.9-slim in Dockerfile and retry. Look at page saying "Hello world".

Other notices

When server is started with mod_wsgi-express start-server instead of direct apache call, error is not thrown. It's kinda strange as it uses httpd internally, so I attached directory (express) with all files generated by this app. It looks like handler is created in a different way, but I can't catch the point.

It doesn't matter whether mod_wsgi is installed with venv or system-wide (venv is used in Dockerfile).

Behavior of app does not depend on wsgi mode: both daemon and embedded mode result in error.

Full log by apache

[Mon Dec 27 11:36:14.440152 2021] [so:warn] [pid 29:tid 140103509888320] AH01574: module wsgi_module is already loaded, skipping
[Mon Dec 27 11:36:14.444285 2021] [wsgi:info] [pid 33:tid 140103509888320] mod_wsgi (pid=33): Starting process 'proof' with uid=999, gid=999 and threads=5.
[Mon Dec 27 11:36:14.444933 2021] [wsgi:info] [pid 33:tid 140103509888320] mod_wsgi (pid=33): Python home /var/www/html/pyenv.
[Mon Dec 27 11:36:14.445047 2021] [wsgi:info] [pid 33:tid 140103509888320] mod_wsgi (pid=33): Initializing Python.
[Mon Dec 27 11:36:14.445286 2021] [mpm_event:notice] [pid 30:tid 140103509888320] AH00489: Apache/2.4.51 (Debian) mod_wsgi/4.9.0 Python/3.10 configured -- resuming normal operations
[Mon Dec 27 11:36:14.445322 2021] [mpm_event:info] [pid 30:tid 140103509888320] AH00490: Server built: 2021-10-07T17:49:44
[Mon Dec 27 11:36:14.445342 2021] [core:notice] [pid 30:tid 140103509888320] AH00094: Command line: '/usr/sbin/apache2'
[Mon Dec 27 11:36:14.465980 2021] [wsgi:info] [pid 33:tid 140103509888320] mod_wsgi (pid=33): Attach interpreter ''.
[Mon Dec 27 11:36:14.479880 2021] [wsgi:info] [pid 33:tid 140103509888320] mod_wsgi (pid=33): Imported 'mod_wsgi'.
[Mon Dec 27 11:36:24.513164 2021] [so:warn] [pid 8:tid 140285522234688] AH01574: module wsgi_module is already loaded, skipping
[Mon Dec 27 11:36:24.518661 2021] [core:warn] [pid 8:tid 140285522234688] AH00098: pid file /var/run/apache2/apache2.pid overwritten -- Unclean shutdown of previous Apache run?
[Mon Dec 27 11:36:24.521400 2021] [wsgi:info] [pid 9:tid 140285522234688] mod_wsgi (pid=9): Starting process 'proof' with threads=5.
[Mon Dec 27 11:36:24.521807 2021] [wsgi:info] [pid 9:tid 140285522234688] mod_wsgi (pid=9): Python home /var/www/html/pyenv.
[Mon Dec 27 11:36:24.522021 2021] [wsgi:info] [pid 9:tid 140285522234688] mod_wsgi (pid=9): Initializing Python.
[Mon Dec 27 11:36:24.522625 2021] [mpm_event:notice] [pid 8:tid 140285522234688] AH00489: Apache/2.4.51 (Debian) mod_wsgi/4.9.0 Python/3.10 configured -- resuming normal operations
[Mon Dec 27 11:36:24.522689 2021] [mpm_event:info] [pid 8:tid 140285522234688] AH00490: Server built: 2021-10-07T17:49:44
[Mon Dec 27 11:36:24.522740 2021] [core:notice] [pid 8:tid 140285522234688] AH00094: Command line: '/usr/sbin/apache2 -D FOREGROUND'
[Mon Dec 27 11:36:24.554672 2021] [wsgi:info] [pid 9:tid 140285522234688] mod_wsgi (pid=9): Attach interpreter ''.
[Mon Dec 27 11:36:24.570737 2021] [wsgi:info] [pid 9:tid 140285522234688] mod_wsgi (pid=9): Imported 'mod_wsgi'.
[Mon Dec 27 11:36:27.238789 2021] [wsgi:info] [pid 9:tid 140285494445824] mod_wsgi (pid=9): Create interpreter 'localhost:8000|'.
[Mon Dec 27 11:36:27.261525 2021] [wsgi:info] [pid 9:tid 140285494445824] [remote 172.22.0.1:44492] mod_wsgi (pid=9, process='proof', application='localhost:8000|'): Loading Python script file '/var/www/html/proof/wsgi.py'.
[Mon Dec 27 11:36:27.279993 2021] [wsgi:error] [pid 9:tid 140285494445824] [remote 172.22.0.1:44492] mod_wsgi (pid=9): Failed to exec Python script file '/var/www/html/proof/wsgi.py'.
[Mon Dec 27 11:36:27.280078 2021] [wsgi:error] [pid 9:tid 140285494445824] [remote 172.22.0.1:44492] mod_wsgi (pid=9): Exception occurred processing WSGI script '/var/www/html/proof/wsgi.py'.
[Mon Dec 27 11:36:27.281223 2021] [wsgi:error] [pid 9:tid 140285494445824] [remote 172.22.0.1:44492] Traceback (most recent call last):
[Mon Dec 27 11:36:27.281294 2021] [wsgi:error] [pid 9:tid 140285494445824] [remote 172.22.0.1:44492]   File "/var/www/html/proof/wsgi.py", line 9, in <module>
[Mon Dec 27 11:36:27.281305 2021] [wsgi:error] [pid 9:tid 140285494445824] [remote 172.22.0.1:44492]     Test('a')
[Mon Dec 27 11:36:27.281326 2021] [wsgi:error] [pid 9:tid 140285494445824] [remote 172.22.0.1:44492] TypeError: Test() takes no arguments

About

Using mod_wsgi with apache leads to broken dataclasses with python3.10

Topics

Resources

Stars

Watchers

Forks