-
Notifications
You must be signed in to change notification settings - Fork 272
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Decorators on classes ignored #729
Comments
Ignoring mod_wsgi, what are you trying to do with this decorator in the first place? There are better ways to monkey patch existing code, but in that very simple example you would be better off using derivation. So can you step back and explain why you are trying to override the constructor method of the class and perhaps can explain a better way of doing that for a start. |
BTW, you know your Apache config is wrong. You have:
but are lacking corresponding |
Your repository which replicates the issue also works perfectly fine for me. Try rebuilding it and use BTW, I would also recommend you ignore the system packages for mod_wsgi and
That still isn't a properly setup container for doing Python web stuff as is missing standard language locales and other stuff required when using Python in a container. |
The error we see is raised from
Using On the other hand I found that the same error raised from Thank you for your help and time spent on this! |
Smells a bit like some C extension is handling an internal error from some C API call but not clearing the error state using:
What can occur is that if the error state is not clear but then a successful response is still returned, that existing error state can affect some operation later on and appear as an error there when it isn't related but is from something that occurred prior. |
FWIW, this triggers the same error: class Greeting:
pass
def new_init(inst, name):
inst.text = f"Hello, {name}\n"
Greeting.__init__ = new_init But this works: class Greeting():
__init__ = None # <- define whatever __init__ here and it works
def new_init(inst, name):
inst.text = f"Hello, {name}\n"
Greeting.__init__ = new_init |
I believe this is a bug in Python subinterpreters: https://bugs.python.org/issue46034 |
Bug was closed in favor of https://bugs.python.org/issue46006 (which has open PR python/cpython#30131). Just for posterity, two fairly simple examples where this fails: from dataclasses import dataclass
@dataclass
class Foo:
tag: str
NULL_FOO = Foo("") # Foo() takes no arguments Because pytz does some trickery with dynamically created lazing loading list classes: from pytz import timezone
DEFAULT_TIMEZONE = pytz.timezone("Europe/Berlin") # pytz.exceptions.UnknownTimeZoneError |
And as an update: The problem was fixed with Python 3.10.2. |
Hello Graham,
We met this issue when trying to upgrade our app to Fedora Linux 35 (which has mod_wsgi 4.9.0 and Python 3.10). After some research, it seems that decorators added to class definitions are somehow ignored, so any modification they would do to the class just wont happen.
For example, the following code raises a
TypeError: Greeting() takes no arguments
when served throughmod_wsgi
running on Fedora Linux 35, but works without errors on Fedora Linux 34 (mod_wsgi 4.7.1, Python 3.9).Serving it with flask's own server or through gunicorn on Fedora Linux 35 also works fine.
Running the code in an interactive interpreter or standalone script also works fine.
I've prepared a reproducer to build the app above both on Fedora Linux 34 and 35.
ATM I have run out of ideas how to continue to debug this. If you could give me some pointers, I would gladly spend the time to research this more.
The text was updated successfully, but these errors were encountered: