#1031928 python3-django-hyperkitty: Javascript not loaded because of HTML error

#1031928#5
Date:
2023-02-25 14:00:50 UTC
From:
To:
Dear Maintainer,

I set up mailman3 including the web interface and the hyperkitty
archiver with Apache2 and a test mailing list.

Upon accessing the archive at
https://<mywebserver>/mailman3/hyperkitty/list/test@<mydomain>/
I immediately noticed that the page was incomplete, showing only
rotating spinners where some of the context should be.

Further investigation showed that the HTML is wrong:

    <script type="text/javascript" src="/mailman3/static/hyperkitty/libs/popper/popper.min.js" />
    <script type="text/javascript" src="/mailman3/static/hyperkitty/libs/bootstrap/javascripts/bootstrap.min.js" />
    ...

In normal HTML (not XHTML) a <script> element needs to be closed with a
</script> tag, the XML-style /> ending is not recognized. The result is
that browsers (at least Firefox and Chromium) ignore all scripts except
the first.

replacing "/>" with "></script>" on the offending lines fixes the
problem

PS: I do notice that those lines are enclosed in
    {% compress js %}...{% endcompress %} so it could also be that that
    doesn't work properly

#1031928#10
Date:
2023-03-02 01:32:55 UTC
From:
To:
Hi Peter,

I'd like to gain some experience with configuring email infrastructure, and
this bug seems like a good opportunity to learn.

I haven't yet been able to reproduce the self-closing HTML script tags; here's
roughly the series of install steps I used (I may have omitted one or two
details) to get the interface up-and-running:

  # apt install mailman3-full
  # vim /etc/mailman3/mailman-web.py  # configure REST API creds
  # ln -s /etc/mailman3/apache.conf /etc/apache2/conf-available/mailman3.conf
  # a2enconf mailman3
  # a2enmod proxy_uwsgi
  # systemctl restart mailman3-web
  # systemctl restart apache2

(note that I also had postfix utilities installed on the system)

That seemed to work: I was able to browse the postorius web interface and see
that I had no mailing lists configured.

Checking the HTML source of the page, I did see some <script> tags -- including
for 'popper.js' -- each of them had a closing </script> tag, as expected.

Could you provide any more information on configuration steps / settings that
may be required to reproduce the problem?

Thanks!
James

#1031928#17
Date:
2023-03-02 18:53:12 UTC
From:
To:
I just did that on a fresh VM to to have a pristine state again.

The problem is only on the "Archives" page (/mailman3/hyperkitty), and
it's not immediately noticable without any archived mailinglists,
however ...

At the bottom of the hyperkitty page I see now:

    <script src="/mailman3/static/hyperkitty/libs/jquery/jquery-1.10.1.min.js"></script>
    <script src="/mailman3/static/hyperkitty/libs/jquery/jquery-ui-1.10.3.custom.min.js"></script>
    <script src="/mailman3/static/CACHE/js/output.e1a49b476a8d.js"></script>

This is ok, but it's not what I saw on the other system. Instead of the
last line with the cached compressed javascript I got the 12 individual
script entries from the template.

So it seems that my suspicion that {% compress js %}...{% endcompress %}
wasn't working properly was correct. But of course that raises the
question why that would fail on one system and work on another. I'll
investigate that and then get back to you.

My process wasn't as straightforward as yours, there was quite a bit of
trial and error involved (for example, I installed postgresql after
mailman3 and then did a dpkg-reconfigure to get mailman3 to use
posgresql instead of sqlite; and I also needed a few attempts to get the
apache config right), however, browsing through the shell history I see
no differences which look relevant.

        hp

#1031928#22
Date:
2023-03-02 19:30:04 UTC
From:
To:
Found it (RTFM helps). I had set DEBUG = True in
/etc/mailman3/mailman-web.py. This implicitly sets COMPRESS_ENABLED =
False, so it was just passing the wrong HTML from the template through
to the browser.

        hp

#1031928#27
Date:
2023-03-02 20:36:10 UTC
From:
To:
Package: python3-django-hyperkitty
Followup-For: Bug #1031928
Control: tags -1 - moreinfo
Control: tags -1 + confirmed
Control: severity -1 important

Perfect, thank you - I can confirm that I see the same errant HTML after
turning off compression in mailman-web.py and restarting the service:

   <script type="text/javascript" src="/mailman3/static/hyperkitty/libs/popper/popper.min.js" />
   <script type="text/javascript" src="/mailman3/static/hyperkitty/libs/bootstrap/javascripts/bootstrap.min.js" />
   ...

I'm lowering the severity by one level because I don't think that this is a
release critical bug for bookworm given that it is a non-default setting, but
please feel free to disagree with me on that.

The patch looks good to me -- and I expect that it should work -- but I haven't
tested it yet to verify that.

#1031928#38
Date:
2023-03-03 11:57:14 UTC
From:
To:
Hi Peter - one more thought from me:

Would you be willing to send your patch to the upstream hyperkitty project[1]
as well?  (likely as a merge request on their GitLab instance)

Since we've found the conditions for the problem to occur and since it looks
like a fairly safe patch, they might welcome it as a fix.

Thanks,
James

[1] - https://gitlab.com/mailman/hyperkitty/

#1031928#43
Date:
2023-03-04 10:23:29 UTC
From:
To:
Sure, but it seems to be fixed in upstream already, presumably because
they use a significantly newer version of django-compressor (4.3.1
instead of 2.4). The newer version of django-compressor reformats
<script .. /> to <script ..></script> even if COMPRESS_ENABLED = False.

        hp

#1031928#48
Date:
2023-03-04 10:58:15 UTC
From:
To:
Can I change the severity of the bug?

Since it only happens if the admin sets DEBUG = True, it won't affect
most users. So normal or even minor seems to be more appropriate than
grave.

        hp

#1031928#53
Date:
2023-03-04 12:21:34 UTC
From:
To:
Package: python3-django-hyperkitty
Followup-For: Bug #1031928
X-Debbugs-Cc: hjp@hjp.at
control commands (as 'pseudoheaders') at the start of your email messages to
bug threads: https://www.debian.org/Bugs/Reporting#additionalpseudoheaders

Fair point.. hmm.  Ideally we'd want test coverage to ensure that it doesn't
happen again, though.

The upstream codebase does appear to assert on the contents[1] of the HTML
response in some cases; something similar could work as a regression test
for this bug.

[1] - https://gitlab.com/mailman/hyperkitty/-/blob/aae84b89184b9ae048ca693d332b7478f8734d4e/hyperkitty/tests/views/test_index.py#L214-220

#1031928#58
Date:
2023-03-04 12:52:20 UTC
From:
To:

#1031928#63
Date:
2023-03-04 20:55:41 UTC
From:
To:
next attempt ...
#1031928#70
Date:
2024-03-17 22:13:14 UTC
From:
To:
Considering the version of django-compressor in bookworm, I think this
bug can be closed.

Feel free to reopen if I'm wrong.

James Addison <jay@jp-hosting.net> wrote on 04/03/2023 at 13:21:34+0100:

#1031928#75
Date:
2024-04-09 12:06:20 UTC
From:
To:
Hi Pierre,

Unfortunately I do not believe that this problem is resolved yet; my
understanding is that the issue appears when DEBUG mode is enabled, meaning
that compression is _disabled_, and so the dependency on django-compressor is
not directly relevant.

The problem originates from some non-well-formed HTML in the hyperkitty
templates.

Regards,
James

#1031928#82
Date:
2024-07-08 21:35:36 UTC
From:
To:
Thanks Pierre-Elliott for opening the bugreport (forwarded) for this upstream.
#1031928#89
Date:
2026-04-17 08:28:56 UTC
From:
To:
After upgrading a working mailman3 installation from bookworm to trixie,
I've been hit by this bug. It has been difficult to find the relevant
information and to workaround it.

For the record (and web search engines):
- I first see this kind of messages in javascript console (firefox dev tools 'F12'):
  Uncaught ReferenceError: setup_overview is not defined
    <anonymous> https://list.domain/mailman3/hyperkitty/list/name@list.domain/:813
    jQuery 13
- Eventually, I found this Debian bug and the related MR:
https://gitlab.com/mailman/hyperkitty/-/merge_requests/708
- I use the info from the MR patch:
https://gitlab.com/mailman/hyperkitty/-/merge_requests/708/diffs?commit_id=ea4bd163272d48d864c1ae64e7c776ca3e430b84
  to patch the debian file /usr/lib/python3/dist-packages/hyperkitty/templates/hyperkitty/base.html
- at this point, trying an access to the archive page results on a server error page
- looking at /var/log/mailman3/web/mailman-web.log, I see the following message:
    ERROR 2026-04-17 10:05:38,906 2023011 django.request Internal Server Error: /mailman3/hyperkitty/list/name@list.domain/
    Traceback (most recent call last):
      File "/usr/lib/python3/dist-packages/django/core/handlers/exception.py", line 55, in inner
        response = get_response(request)
      File "/usr/lib/python3/dist-packages/django/core/handlers/base.py", line 197, in _get_response
        response = wrapped_callback(request, *callback_args, **callback_kwargs)
      File "/usr/lib/python3/dist-packages/hyperkitty/lib/view_helpers.py", line 137, in inner
        return func(request, *args, **kwargs)
      File "/usr/lib/python3/dist-packages/hyperkitty/views/mlist.py", line 240, in overview
        return render(request, "hyperkitty/overview.html", context)
      File "/usr/lib/python3/dist-packages/django/shortcuts.py", line 24, in render
        content = loader.render_to_string(template_name, context, request, using=using)
      File "/usr/lib/python3/dist-packages/django/template/loader.py", line 62, in render_to_string
        return template.render(context, request)
               ~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^
      File "/usr/lib/python3/dist-packages/django/template/backends/django.py", line 61, in render
        return self.template.render(context)
               ~~~~~~~~~~~~~~~~~~~~^^^^^^^^^
      File "/usr/lib/python3/dist-packages/django/template/base.py", line 175, in render
        return self._render(context)
               ~~~~~~~~~~~~^^^^^^^^^
      File "/usr/lib/python3/dist-packages/django/template/base.py", line 167, in _render
        return self.nodelist.render(context)
               ~~~~~~~~~~~~~~~~~~~~^^^^^^^^^
      File "/usr/lib/python3/dist-packages/django/template/base.py", line 1005, in render
        return SafeString("".join([node.render_annotated(context) for node in self]))
                                   ~~~~~~~~~~~~~~~~~~~~~^^^^^^^^^
      File "/usr/lib/python3/dist-packages/django/template/base.py", line 966, in render_annotated
        return self.render(context)
               ~~~~~~~~~~~^^^^^^^^^
      File "/usr/lib/python3/dist-packages/django/template/loader_tags.py", line 157, in render
        return compiled_parent._render(context)
               ~~~~~~~~~~~~~~~~~~~~~~~^^^^^^^^^
      File "/usr/lib/python3/dist-packages/django/template/base.py", line 167, in _render
        return self.nodelist.render(context)
               ~~~~~~~~~~~~~~~~~~~~^^^^^^^^^
      File "/usr/lib/python3/dist-packages/django/template/base.py", line 1005, in render
        return SafeString("".join([node.render_annotated(context) for node in self]))
                                   ~~~~~~~~~~~~~~~~~~~~~^^^^^^^^^
      File "/usr/lib/python3/dist-packages/django/template/base.py", line 966, in render_annotated
        return self.render(context)
               ~~~~~~~~~~~^^^^^^^^^
      File "/usr/lib/python3/dist-packages/compressor/templatetags/compress.py", line 160, in render
        return self.render_compressed(
               ~~~~~~~~~~~~~~~~~~~~~~^
            context, self.kind, self.mode, forced=forced, log=log, verbosity=verbosity
            ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
        )
        ^
      File "/usr/lib/python3/dist-packages/compressor/templatetags/compress.py", line 106, in render_compressed
        return self.render_offline(context)
               ~~~~~~~~~~~~~~~~~~~^^^^^^^^^
      File "/usr/lib/python3/dist-packages/compressor/templatetags/compress.py", line 84, in render_offline
        raise OfflineGenerationError(
        ...<4 lines>...
        )
    compressor.exceptions.OfflineGenerationError: You have offline compression enabled but key "530ac53ad8e49e22ec5ebf23242485308e03ad03f01e2722774cd6c7b02b78c3" is missing from offline manifest. You may need to run "python manage.py compress". Here is the original content:


        <script type="text/javascript" src="/mailman3/static/hyperkitty/libs/bootstrap/javascripts/bootstrap.bundle.min.js" ></script>
        <script type="text/javascript" src="/mailman3/static/hyperkitty/libs/mousetrap/mousetrap.min.js" ></script>
        <script type="text/javascript" src="/mailman3/static/hyperkitty/libs/jquery.expander.js" ></script>
        <script type="text/javascript" src="/mailman3/static/hyperkitty/libs/d3.v2.min.js" ></script>
        <script type="text/javascript" src="/mailman3/static/hyperkitty/libs/jquery.hotkeys.js" ></script>
        <script type="text/javascript" src="/mailman3/static/django-mailman3/js/main.js" ></script>
        <script type="text/javascript" src="/mailman3/static/hyperkitty/js/hyperkitty-common.js" ></script>
        <script type="text/javascript" src="/mailman3/static/hyperkitty/js/hyperkitty-index.js" ></script>
        <script type="text/javascript" src="/mailman3/static/hyperkitty/js/hyperkitty-overview.js" ></script>
        <script type="text/javascript" src="/mailman3/static/hyperkitty/js/hyperkitty-thread.js" ></script>
        <script type="text/javascript" src="/mailman3/static/hyperkitty/js/hyperkitty-userprofile.js" ></script>

- I did not know how to rebuild the cache. According to the message, I was server-side
  and, indeed, cleaning browser cache did not help
  I did not know where to try to run the suggested command and under which user.
- restarting apache2.service and mailman3-web.service was not enough
- I success using the following commands (not sure which one really helps):
    dpkg-reconfigure python3-django-hyperkitty
    dpkg-reconfigure python3-mailman-hyperkitty
    dpkg-reconfigure mailman3-web            # keeping the current database conf

I was long and paintfull. It is a pitty such fix was not directly included in a fixed package in stable.

  Regards,
    Vincent