mailer: Broken in 3.8 due to bad import from marrow/cgi

Looks like it’s broken on python 3.8.1 currently.

Installs fine:

❯ pip install marrow.mailer --user                                                                                                         
Collecting marrow.mailer
  Using cached https://files.pythonhosted.org/packages/8c/37/961103b20bad1a8af86fa67a53748c2bf26e9e242a79fa89dc762d374ea6/marrow.mailer-4.0.3-py2.py3-none-any.whl
Collecting marrow.util<2.0
  Using cached https://files.pythonhosted.org/packages/d2/19/630a0984ba6d5dc4432ed45d2c9ab8752542fa6ba1590a0e72d1fb742c2e/marrow.util-1.2.3.tar.gz
Installing collected packages: marrow.util, marrow.mailer
    Running setup.py install for marrow.util ... done
Successfully installed marrow.mailer-4.0.3 marrow.util-1.2.3

Running a script with the example code:

from marrow.mailer import Mailer, Message

mailer = Mailer(dict(
        transport = dict(
                use = 'smtp',
                host = 'localhost')))
mailer.start()

message = Message(author="user@example.com", to="user-two@example.com")
message.subject = "Testing Marrow Mailer"
message.plain = "This is a test."
mailer.send(message)

mailer.stop()
Traceback (most recent call last):
  File "/home/liam/projects/soc_siem_bi_integration/soc_scripts/cleanup.py", line 8, in <module>
    from marrow.mailer import Mailer, Message
  File "/home/liam/.local/lib/python3.8/site-packages/marrow/mailer/__init__.py", line 12, in <module>
    from marrow.mailer.message import Message
  File "/home/liam/.local/lib/python3.8/site-packages/marrow/mailer/message.py", line 21, in <module>
    from marrow.mailer.address import Address, AddressList, AutoConverter
  File "/home/liam/.local/lib/python3.8/site-packages/marrow/mailer/address.py", line 12, in <module>
    from marrow.util.compat import basestring, unicode, unicodestr, native
  File "/home/liam/.local/lib/python3.8/site-packages/marrow/util/compat.py", line 33, in <module>
    from cgi import parse_qsl
ImportError: cannot import name 'parse_qsl' from 'cgi' (/usr/lib/python3.8/cgi.py)

If I go diving into compat.py and change from cgi import parse_qsl to from urllib.parse import parse_qsl, it works fine. This is makes sense, given Python 3.8 notes:

parse_qs, parse_qsl, and escape are removed from the cgi module. They are deprecated in Python 3.2 or older. They should be imported from the urllib.parse and html modules instead.

I don’t know the ramifications of using urllib.parse over html, though.

Util is archived, otherwise I would have raised the issue there /shrug.

About this issue

  • Original URL
  • State: closed
  • Created 4 years ago
  • Reactions: 7
  • Comments: 27 (11 by maintainers)

Most upvoted comments

Hey everyone,

I ran into this issue today. Rather than switching to a fork, you can temporarily fix this error by adding these lines at the top of the file (before importing Mailer):

import sys  # isort:skip

sys.modules["cgi.parse_qsl"] = None

I’m sorry, I cannot have further discussions with a dictator who locks issues as off-topic when confronted with actual arguments while advocating about unrelated technological limitations of SMTP, HTTP APIs, mime types and reliability, none of which I even touched on, nor even mentioned Sorry for wasting your time

@GertBurger Author said the change is “trivial” 4 months ago here https://github.com/marrow/mailer/issues/90#issuecomment-617994426

The problem isn’t parse* being imported from the wrong location; it’s never used within this package. It should be fairly clear the PR would instead need to simply remove marrow.util. It can be outright deleted.

(Bunch → trivial “attribute access dictionary” implementation required, load_object is actually marrow.package:load, boolean is a dictionary lookup w/ fallback, all compat just disappears, and that’s… that’s basically it.)

I must have misunderstood the meaning of the word.

And he got offended and closed the issue as “off topic” when asked if the project is unmaintained

@iamareebjamal You submit a second issue that duplicates this one passive-aggressively, claim superior knowledge over the codebase than the original author regarding what can and can not be deleted after demonstrating an inability to search properly, then become offended when the duplicate is closed/locked, after the truth of modern e-mail delivery is laid out before you in answer to the “alternatives” question. I really do not know how much more accomodating I could possibly be.

“MIME types” were never mentioned. I do not comprehend your psychology. Good luck, and apologies to the original submitter and additional commentor for being forced to have this play out on their issue. This issue will remain open until I’ve integrated the removal of marrow.util into develop.