Debian packages problem: traceback in themes/__init__.py" line 831: AttributeError
Hi Paul, in April you posted following error on the moin-user mailing list:
I now get the following errors when deploying a wiki using Apache and mod_wsgi:
File "/usr/lib/python3/dist-packages/moin/themes/__init__.py", line 831, in setup_jinja_env "item_name": request.view_args.get("item_name", ""), ^^^^^^^^^^^^^^^^^^^^^ AttributeError: 'NoneType' object has no attribute 'get'
Using the built-in Web server with "moin run" works fine, however.
If you still need support, may I ask you to send me more details on how to reconstruct this error? What version of Debian are you using and where can I find the moin package for testing? Regards, Ulrich
On Wednesday, 10 July 2024 21:06:39 CEST Ulrich B. wrote:
If you still need support, may I ask you to send me more details on how to reconstruct this error?
I haven't really looked into this since April, given that my level of motivation dropped below the necessary threshold to keep looking at it.
What version of Debian are you using and where can I find the moin package for testing?
I have been using the unstable version of Debian because this is where packaging efforts are directed when software is not yet available in the Debian software distribution. I previously made packages available here: https://salsa.debian.org/moin-team/moin/-/jobs/4925860/artifacts/browse/aptl... My message from 10th September 2023 with the subject... [moin-devel] Debian packages (Re: moin2 release with core functionality) ...describes the considerations when using packages published in this way. Since reading your message, I have looked again at the packaging and have finally managed to make setuptools_scm work with the Debian package building mechanisms. Despite this being hugely irritating, resolving this only has the benefit of avoiding a small amount of work when fixing up the Moin sources. In any case, trying Moin out in the Debian unstable environment has highlighted some places that probably need fixing. First of all, in moin/ utils/send_file.py, in the send_file function, there is usage of current_app.use_x_sendfile which may not be compatible with Flask 3.0. Having eliminated this usage, albeit without fixing the problem, I then encounter the previous issue with request.view_args. From what I understand of the Request initialisation in flask/wrappers.py, this is initially set to None. (I see that enthusiasm for type annotations is slowly turning Python into C++.) It seems that view_args is set in flask/ctx.py, in the match_request method of RequestContext by unpacking a result tuple from a URL adapter. The URL adapter is apparently created for the context using the create_url_adapter method of Flask in flask/app.py. I imagine that there must be some kind of difference between the initialisation of the mod_wsgi application and that of the built-in server, but I think that it might be quicker for someone more familiar with the code to locate where that difference might be. Thanks for following up. Paul
Hi Paul, thanks for feedback. Am 12.07.24 um 16:57 schrieb Paul Boddie:
In any case, trying Moin out in the Debian unstable environment has highlighted some places that probably need fixing. First of all, in moin/ utils/send_file.py, in the send_file function, there is usage of current_app.use_x_sendfile which may not be compatible with Flask 3.0. Usage of current_app.use_x_sendfile has been removed and we are already using Flask >= 3.0.0. I imagine that there must be some kind of difference between the initialisation of the mod_wsgi application and that of the built-in server, but I think that it might be quicker for someone more familiar with the code to locate where that difference might be.
I have successfully created a moin2 wiki with uwsgi on a web host, see https://moinmo.in/MoinMoin2/SetupOnWebhost. I will check a setup with Apache and mod_wsgi. Regards, Ulrich
On Friday, 12 July 2024 20:13:16 CEST Ulrich B. wrote:
Am 12.07.24 um 16:57 schrieb Paul Boddie:
In any case, trying Moin out in the Debian unstable environment has highlighted some places that probably need fixing. First of all, in moin/ utils/send_file.py, in the send_file function, there is usage of current_app.use_x_sendfile which may not be compatible with Flask 3.0.
Usage of current_app.use_x_sendfile has been removed and we are already using Flask >= 3.0.0.
Well, use_x_sendfile is definitely there in 2.0.0a1: https://github.com/moinwiki/moin/blob/2.0.0a1/src/moin/utils/send_file.py#L1... But this has obviously been fixed since, so nothing for me to worry about in future. [...]
I have successfully created a moin2 wiki with uwsgi on a web host, see https://moinmo.in/MoinMoin2/SetupOnWebhost. I will check a setup with Apache and mod_wsgi.
I got it to work previously, in fact, but then Debian upgraded Flask and various other packages, needing Moin to be modified, and so on. Thanks again for following up. Paul
On Friday, 12 July 2024 21:03:22 CEST Paul Boddie wrote:
On Friday, 12 July 2024 20:13:16 CEST Ulrich B. wrote:
I have successfully created a moin2 wiki with uwsgi on a web host, see https://moinmo.in/MoinMoin2/SetupOnWebhost. I will check a setup with Apache and mod_wsgi.
I got it to work previously, in fact, but then Debian upgraded Flask and various other packages, needing Moin to be modified, and so on.
Just to follow up, I have now tested Moin with mod_wsgi and the error with request.view_args no longer occurs. I don't know why I experienced the errors before, unfortunately. Sorry not to have reported back sooner! Paul
On Monday, 22 July 2024 01:31:24 CEST Paul Boddie wrote:
Just to follow up, I have now tested Moin with mod_wsgi and the error with request.view_args no longer occurs. I don't know why I experienced the errors before, unfortunately.
Just to follow up again, I identified the error and it is a trivial but annoying one. Having set up a wiki instance, I tried to visit it at... http://127.0.0.1/20240814 This caused the error where request.view_args is None. Introducing some debugging statements indicated that the initial exception occurs in flask/ ctx.py in the RequestContext.match_request method, this being an HTTPException instance encoding a "308 Permanent Redirect" condition. The exception is caught and set on the request's routing_exception attribute, but then request processing continues in flask/app.py in the Flask.preprocess_request method, leading to further processing without a usable view_args object in the Moin code itself. Ultimately, Moin's theme code causes an exception that is not gracefully handled. All of this suggested that the following location might work instead, and it indeed does: http://127.0.0.1/20240814/ I presumably tested using the different URL forms on different occasions, giving inconsistent results. However, I don't think that the redirect condition should cause an internal error, but I don't currently have a remedy that would fix this behaviour, either. Paul
Am 14.08.24 um 23:59 schrieb Paul Boddie:
Just to follow up again, I identified the error and it is a trivial but annoying one. Having set up a wiki instance, I tried to visit it at...
This caused the error where request.view_args is None. Introducing some debugging statements indicated that the initial exception occurs in flask/ ctx.py in the RequestContext.match_request method, this being an HTTPException instance encoding a "308 Permanent Redirect" condition.
There is an option to prevent the redirect, please see https://github.com/moinwiki/moin/issues/1737. Hopefully this fixes the problem. Regards, Ulrich
On Thursday, 12 September 2024 20:09:28 CEST Ulrich B. wrote:
There is an option to prevent the redirect, please see https://github.com/moinwiki/moin/issues/1737. Hopefully this fixes the problem.
I manually introduced the one-line change and it does indeed fix the error. Thanks for looking into this, and I look forward to the next release! Paul
participants (2)
-
Paul Boddie -
Ulrich B.