Buffer capture bug on Ubuntu 22.04.5 LTS #411
Replies: 2 comments 3 replies
-
hi - it is extremely unlikely that the ubuntu distribution in use is having an effect on the behavior of Mako. the versions of other packages being installed is maybe a little bit more possible, but Mako really doesnt have any dependencies other than markupsafe, and if you are using the same versions of things on other OSes, there really is very little possibility that a specific linux distro by itself is causing the problem. The way I'd test specific linux distros is by running the same program in Docker / podman containers that run these different dists. then again, if there was something OS-specific making something random happen, the kernel itself would be something to look at, but in my 25 years of doing Python I've never seen any issue of any kind that was dependent on kernel versions. only python versions, differences between linux/windows/mac, differences of locale, etc. linux kernel or OS dist? never. mostly what is suspect is the description of the problem:
this sounds like the kind of rearrangement we see in a web browser when javascript is involved or viewsource: is involved. Since you dont have any self-contained example and are only pointing at web framework code, is it possible you are only testing this in a browser? I would recommend testing the templating code in isolation of any kind of client/server setup and ideally in isolation of a web framework. at the very least, if you are looking at the output of a web framework, use the |
Beta Was this translation helpful? Give feedback.
-
Looks like there is a Apache reverse proxy in the mix. Bypassing this eliminates the problem. So there is no issue with mako. Thanks again, your reply was a big help. |
Beta Was this translation helpful? Give feedback.
-
I'm only guessing at the source of the problem because reproducing the bug is tricky, but perhaps there's something you can do with this report anyway. Apologies also for not working this down to a minimal example. I spent too much time trying to reproduce this on a Debian system, and finding out what is really happening, and just don't have time right now to do more. I am filing this report to have a record of the issue and something to work from.
I've a HTML
<span>
element that contains "custom tags", %defs called from a namespace, which utilize ${capture(caller.body) | n,trim}. When the template is rendered the result of the custom tags is placed after the closing</span>
element -- but only on Ubuntu 22.04.5 LTS. This is especially strange because this did not happen when the custom tags were enclosed in a<div>
, adding the<span>
between the<div>
and the custom tag brought out the behavior.I'm supplying code by URL below. The domain will soon change from "papio-test" to "papio", so readers may need to adjust the URLs given.
The defs are lines 41 through 55 of https://papio-test.biology.duke.edu/gitweb/?p=pgwui_common;a=blob;f=src/pgwui_common/templates/lib.mak;h=266b16a786c0bb016b0ce0fd743d3f7ece1dff5d;hb=2a8e2abe9c6af2b679fb5e8f494ad5d82e693ed5
Their usage is lines 171 through 197 of
(https://papio-test.biology.duke.edu/gitweb/?p=pgwui_sql;a=blob;f=src/pgwui_sql/templates/sql.mak;h=bbe9cb927a40b8ef9108c39fc2a1e3ff3a9d85dd;hb=3028886cf78bd3a2c1333167f18e57e82c7071bc
The rendered result (or portion thereof) is:
Note how the rendered span contains only whitespace, and is then followed by the tag output. What's expected, and what happens on Debian, is that the closing span tag is right before the closing div tag.
This happens on:
Ubuntu 22.04.5 LTS
Python 3.10.12
Kernel Linux bio-alberts-03.biology.duke.edu 5.15.0-122-generic #132-Ubuntu SMP Thu Aug 29 13:45:52 UTC 2024 x86_64 x86_64 x86_64 GNU/Linux
Packages installed in the virtualenv are:
Mako-1.3.5 PasteDeploy-3.1.0 attrs-24.2.0 beaker-1.13.0 hupper-1.12.1 markupsafe-2.1.5 pgwui_bulk_upload-0.23.0 pgwui_common-0.23.0 pgwui_copy-0.23.0 pgwui_core-0.23.0 pgwui_logout-0.23.0 pgwui_server-0.23.0 pgwui_sql-0.23.0 pgwui_upcen-0.23.0 pgwui_upload-0.23.0 pgwui_upload_core-0.23.0 plaster-1.1.2 plaster-pastedeploy-1.0.1 plaster-yaml-1.0.2 psycopg-3.2.3 pyramid-2.0.2 pyramid-beaker-0.9 pyramid-mako-1.1.0 pyyaml-6.0.2 translationstring-1.4 typing-extensions-4.12.2 venusian-3.1.0 waitress-3.0.0 webob-1.8.8 wtforms-3.1.2 zope.deprecation-5.0 zope.interface-7.0.3
The problem still occurs when whitespace is removed from between the span open and closing tags and the span content.
I cannot reproduce this on Debian 12.7, kernel Linux slate 6.1.0-25-amd64 #1 SMP PREEMPT_DYNAMIC Debian 6.1.106-3 (2024-08-26) x86_64 GNU/Linux, either with python 3.11.2 or using pyenv with python 3.10.12. The same versions of the same packages are installed in debian, although the venv on debian does contain some additional packages.
On the Debian system everything works as expected. This seems to hint that the problem is outside of mako.
I could understand how some buffering problem causes output to appear later in the output stream than expected. But what's so odd here is that, regardless of whitespace removal, the output appears just after the closing tag of an element that's supposed to contain the rendered content, and does in the template source. Not to mention not being able to reproduce the problem using as identical a software stack as (or almost as) possible.
Ideas, suggested work-arounds, etc., would be appreciated. (Even though I don't anticipate being able to devote more than a few minutes at a time to resolving this in the immediate future.)
Beta Was this translation helpful? Give feedback.
All reactions