Bug 2252567

Summary: Python 3.12.0-1 breaks Flask apps running from subinterpreters
Product: [Fedora] Fedora Reporter: Joel Uckelman <uckelman>
Component: python3.12Assignee: Miro Hrončok <mhroncok>
Status: CLOSED ERRATA QA Contact:
Severity: medium Docs Contact:
Priority: unspecified    
Version: 39CC: cstratak, mhroncok, python-maint, python-packagers-sig, thrnciar, vstinner
Target Milestone: ---Keywords: Regression, Upgrades
Target Release: ---   
Hardware: x86_64   
OS: Linux   
URL: https://github.com/python/cpython/issues/110279
Whiteboard:
Fixed In Version: python3.12-3.12.1-1.fc39 Doc Type: If docs needed, set a value
Doc Text:
Story Points: ---
Clone Of: Environment:
Last Closed: 2023-12-19 01:11:35 UTC Type: ---
Regression: --- Mount Type: ---
Documentation: --- CRM:
Verified Versions: Category: ---
oVirt Team: --- RHEL 7.3 requirements from Atomic Host:
Cloudforms Team: --- Target Upstream Version:
Embargoed:

Description Joel Uckelman 2023-12-02 16:18:55 UTC
On upgrading from F38 to F39, all Flask apps fail this way:

[Sat Dec 02 15:47:16.161715 2023] [wsgi:error] [pid 1196:tid 1590] [remote 92.25.120.97:49430] mod_wsgi (pid=1196): Exception occurred processing WSGI script '/home/site/dmnes-site/viewer.wsgi'.
[Sat Dec 02 15:47:16.162222 2023] [wsgi:error] [pid 1196:tid 1590] [remote 92.25.120.97:49430] Traceback (most recent call last):
[Sat Dec 02 15:47:16.162680 2023] [wsgi:error] [pid 1196:tid 1590] [remote 92.25.120.97:49430]   File "/home/site/dmnes-site/viewer.wsgi", line 7, in <module>
[Sat Dec 02 15:47:16.162693 2023] [wsgi:error] [pid 1196:tid 1590] [remote 92.25.120.97:49430]     from viewer import app as application
[Sat Dec 02 15:47:16.162705 2023] [wsgi:error] [pid 1196:tid 1590] [remote 92.25.120.97:49430]   File "/home/site/dmnes-site/viewer.py", line 20, in <module>
[Sat Dec 02 15:47:16.162709 2023] [wsgi:error] [pid 1196:tid 1590] [remote 92.25.120.97:49430]     app = Flask(__name__)
[Sat Dec 02 15:47:16.162713 2023] [wsgi:error] [pid 1196:tid 1590] [remote 92.25.120.97:49430]           ^^^^^^^^^^^^^^^
[Sat Dec 02 15:47:16.162722 2023] [wsgi:error] [pid 1196:tid 1590] [remote 92.25.120.97:49430]   File "/usr/lib/python3.12/site-packages/flask/app.py", line 709, in __init__
[Sat Dec 02 15:47:16.162726 2023] [wsgi:error] [pid 1196:tid 1590] [remote 92.25.120.97:49430]     self.add_url_rule(
[Sat Dec 02 15:47:16.162735 2023] [wsgi:error] [pid 1196:tid 1590] [remote 92.25.120.97:49430]   File "/usr/lib/python3.12/site-packages/flask/scaffold.py", line 50, in wrapper_func
[Sat Dec 02 15:47:16.162739 2023] [wsgi:error] [pid 1196:tid 1590] [remote 92.25.120.97:49430]     return f(self, *args, **kwargs)
[Sat Dec 02 15:47:16.162772 2023] [wsgi:error] [pid 1196:tid 1590] [remote 92.25.120.97:49430]            ^^^^^^^^^^^^^^^^^^^^^^^^
[Sat Dec 02 15:47:16.162781 2023] [wsgi:error] [pid 1196:tid 1590] [remote 92.25.120.97:49430]   File "/usr/lib/python3.12/site-packages/flask/app.py", line 1357, in add_url_rule
[Sat Dec 02 15:47:16.162785 2023] [wsgi:error] [pid 1196:tid 1590] [remote 92.25.120.97:49430]     self.url_map.add(rule)
[Sat Dec 02 15:47:16.162794 2023] [wsgi:error] [pid 1196:tid 1590] [remote 92.25.120.97:49430]   File "/usr/lib/python3.12/site-packages/werkzeug/routing/map.py", line 174, in add
[Sat Dec 02 15:47:16.162797 2023] [wsgi:error] [pid 1196:tid 1590] [remote 92.25.120.97:49430]     rule.bind(self)
[Sat Dec 02 15:47:16.162805 2023] [wsgi:error] [pid 1196:tid 1590] [remote 92.25.120.97:49430]   File "/usr/lib/python3.12/site-packages/werkzeug/routing/rules.py", line 560, in bind
[Sat Dec 02 15:47:16.162809 2023] [wsgi:error] [pid 1196:tid 1590] [remote 92.25.120.97:49430]     self.compile()
[Sat Dec 02 15:47:16.162817 2023] [wsgi:error] [pid 1196:tid 1590] [remote 92.25.120.97:49430]   File "/usr/lib/python3.12/site-packages/werkzeug/routing/rules.py", line 688, in compile
[Sat Dec 02 15:47:16.162821 2023] [wsgi:error] [pid 1196:tid 1590] [remote 92.25.120.97:49430]     RulePart(
[Sat Dec 02 15:47:16.162837 2023] [wsgi:error] [pid 1196:tid 1590] [remote 92.25.120.97:49430] TypeError: RulePart() takes no arguments


Reproducible: Always

Steps to Reproduce:
1. Send HTTP GET to Flask app
Actual Results:  
Error, as above.

Expected Results:  
Page is served successfully.

The error happens on a @dataclass in werkzeug. Apparently Python 3.12.0 has broken initialization of dataclasses in subinterpreters, as detailed here:

https://github.com/python/cpython/issues/110279

The bug is already fixed, so only needs to be packaged.

There's no workaround available in the meantime---we can't go back to Python 3.11 because mod_wsgi can't be used with any version of Python other than the one it was compiled for.

Comment 2 Miro Hrončok 2023-12-05 13:30:52 UTC
Joel, are you able to test the build and verify the fix?

dnf upgrade https://kojipkgs.fedoraproject.org/work/tasks/753/109940753/python3-libs-3.12.0-3.fc39.x86_64.rpm https://kojipkgs.fedoraproject.org/work/tasks/753/109940753/python3-3.12.0-3.fc39.x86_64.rpm

(add more subpackages if you have them installed)

Comment 3 Joel Uckelman 2023-12-05 21:04:49 UTC
Thanks for pursuing this promptly. I ought to be able to try it and report back tomorrow.

Comment 4 Joel Uckelman 2023-12-08 14:41:55 UTC
I've tested the build with a minimal Flask app and can confirm that with python3 3.12.0-1, I get the error as reported, and with the builds the app works correctly with no errors.

Thanks very much for fixing this problem!

Here's my minimal test case, if you're interested:


app.py:
```
from flask import Flask

app = Flask(__name__)

@app.route('/')
def front()
    return "hey"
```

app.wsgi:
```
import os
import sys

sys.path.append(os.path.dirname(__file__))

from app import app as application
```

Apache conf:
```
WSGIDaemonProcess app
WSGIScriptAlias /app /var/www/html/app.wsgi
```

Comment 5 Fedora Update System 2023-12-09 17:00:54 UTC
FEDORA-2023-c209acd8a1 has been submitted as an update to Fedora 39. https://bodhi.fedoraproject.org/updates/FEDORA-2023-c209acd8a1

Comment 6 Fedora Update System 2023-12-10 02:19:16 UTC
FEDORA-2023-c209acd8a1 has been pushed to the Fedora 39 testing repository.
Soon you'll be able to install the update with the following command:
`sudo dnf upgrade --enablerepo=updates-testing --refresh --advisory=FEDORA-2023-c209acd8a1`
You can provide feedback for this update here: https://bodhi.fedoraproject.org/updates/FEDORA-2023-c209acd8a1

See also https://fedoraproject.org/wiki/QA:Updates_Testing for more information on how to test updates.

Comment 7 Fedora Update System 2023-12-19 01:11:35 UTC
FEDORA-2023-c209acd8a1 has been pushed to the Fedora 39 stable repository.
If problem still persists, please make note of it in this bug report.