[Bug 6956] New: ui.warn dies with TypeError on mod-wsgi

mercurial-bugs at mercurial-scm.org mercurial-bugs at mercurial-scm.org
Wed Jan 22 16:55:07 UTC 2025


https://bz.mercurial-scm.org/show_bug.cgi?id=6956

            Bug ID: 6956
           Summary: ui.warn dies with TypeError on mod-wsgi
           Product: Mercurial
           Version: 6.8.2
          Hardware: PC
                OS: Linux
            Status: UNCONFIRMED
          Severity: bug
          Priority: wish
         Component: Mercurial
          Assignee: bugzilla at mercurial-scm.org
          Reporter: jcristau at debian.org
                CC: mercurial-devel at mercurial-scm.org
    Python Version: ---

mercurial warnings in hgweb seem to turn into exceptions as they fail to write
to stderr:

```
  File "/var/hg/venv_hgweb/lib64/python3.6/site-packages/mercurial/ui.py", line
1911, in warn
    self._writemsg(self._fmsgerr, type=b'warning', *msg, **opts)
  File "/var/hg/venv_hgweb/lib64/python3.6/site-packages/mercurial/ui.py", line
1342, in _writemsg
    _writemsgwith(self._write, dest, *args, **opts)
  File "/var/hg/venv_hgweb/lib64/python3.6/site-packages/mercurial/ui.py", line
2347, in _writemsgwith
    write(dest, *args, **opts)
  File "/var/hg/venv_hgweb/lib64/python3.6/site-packages/mercurial/ui.py", line
1285, in _write 
    self._writenobuf(dest, *args, **opts)
  File "/var/hg/venv_hgweb/lib64/python3.6/site-packages/mercurial/ui.py", line
1310, in _writenobuf
    dest.write(msg)
  File
"/var/hg/venv_hgweb/lib64/python3.6/site-packages/mercurial/utils/procutil.py",
line 138, in write
    c = write1(m[total_written:])
TypeError: write() argument 1 must be read-only bytes-like object, not
memoryview
```

As far as I can tell, mod-wsgi replaces sys.stderr with its own log object
(https://github.com/GrahamDumpleton/mod_wsgi/blob/4.6.5/src/server/wsgi_interp.c#L540).
The write method then uses PyArg_ParseTuple(..., "s#:write", ...)
(https://github.com/GrahamDumpleton/mod_wsgi/blob/4.6.5/src/server/wsgi_logger.c#L348)
which doesn't like the memoryview that's passed by hg.

Looking at newer versions of mod-wsgi and the current python docs
(https://docs.python.org/3/c-api/arg.html#c-arg-borrowed-buffer) this looks
like it would still be relevant there.

[See https://bugzilla.mozilla.org/show_bug.cgi?id=1943083]

-- 
You are receiving this mail because:
You are on the CC list for the bug.


More information about the Mercurial-devel mailing list