Closed Bug 1677422 Opened 4 years ago Closed 3 years ago

AttributeError: module 'cgi' has no attribute 'escape' when using mozlog

Categories

(Testing :: Mozbase, defect, P2)

Default
defect

Tracking

(firefox85 fixed)

RESOLVED FIXED
85 Branch
Tracking Status
firefox85 --- fixed

People

(Reporter: hermes.cheng, Assigned: bc)

References

(Blocks 1 open bug)

Details

Attachments

(1 file)

User Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/86.0.4240.183 Safari/537.36

Steps to reproduce:

  1. use mozlog in my test automation project.
  2. use parameter "--log-html LOG_HTML" to generate html report

My project is using Python 3.8.

Actual results:

Got errors like below.

mozlog.structuredlog: Failure calling log handler:
Traceback (most recent call last):
File "/Users/hermesc/workspace/QA/kapic/.v3.0/lib/python3.8/site-packages/mozlog/structuredlog.py", line 274, in _handle_log
handler(data)
File "/Users/hermesc/workspace/QA/kapic/.v3.0/lib/python3.8/site-packages/mozlog/handlers/base.py", line 74, in call
formatted = self.formatter(data)
File "/Users/hermesc/workspace/QA/kapic/.v3.0/lib/python3.8/site-packages/mozlog/handlers/base.py", line 42, in call
return self.inner(item)
File "/Users/hermesc/workspace/QA/kapic/.v3.0/lib/python3.8/site-packages/mozlog/reader.py", line 74, in call
return handler(data)
File "/Users/hermesc/workspace/QA/kapic/.v3.0/lib/python3.8/site-packages/mozlog/formatters/html/html.py", line 105, in test_end
self.make_result_html(data)
File "/Users/hermesc/workspace/QA/kapic/.v3.0/lib/python3.8/site-packages/mozlog/formatters/html/html.py", line 208, in make_result_html
log.append(raw(cgi.escape(line)))
AttributeError: module 'cgi' has no attribute 'escape'

Expected results:

it should generate html report without any exception.

It looks like we can use html to replace cgi like below.

import html
(skip)
                        log.append(html.span(raw(html.escape(line)), class_="error"))
                    else:
                        log.append(raw(html.escape(line)))

Fabrice,

Do you know who can help fix this and publish it to PyPi?

Flags: needinfo?(fabrice)

According to https://wiki.mozilla.org/Auto-tools/Projects/Mozbase it is maintained by Will Lachance (:wlach) and Andrew Halberstadt (:ahal)

Flags: needinfo?(fabrice)
Component: Untriaged → Mozbase
Product: Firefox → Testing
Flags: needinfo?(wlachance)
Flags: needinfo?(ahal)

Yes, I can help review and publish if you could submit a patch to Phabricator! Looks like cgi.escape was removed in Python 3.8. So html.escape is the correct replacement there. Couple things to bear in mind:

  1. We should try to maintain py2 compat for now (though I'm not aware of anything in-tree using this formatter.. so maybe it's fine to drop it).
  2. There's already a global variable called html in that module. We'll need to rename it or use import html as
Flags: needinfo?(wlachance)
Flags: needinfo?(ahal)

The severity field is not set for this bug.
:bc, could you have a look please?

For more information, please visit auto_nag documentation.

Flags: needinfo?(bob)

I'll take it as part of my python3 work. eta this week sometime.

Assignee: nobody → bob
Blocks: testing-py3
Severity: -- → S3
Status: UNCONFIRMED → ASSIGNED
Ever confirmed: true
Flags: needinfo?(bob)
Priority: -- → P2
Version: Firefox 84 → Default
Pushed by bclary@mozilla.com:
https://hg.mozilla.org/integration/autoland/rev/18f7558b7bb0
python3 - [mozlog] use cgi.escape for Python2, html.escape for Python3. r=jgraham
Status: ASSIGNED → RESOLVED
Closed: 3 years ago
Resolution: --- → FIXED
Target Milestone: --- → 85 Branch
You need to log in before you can comment on or make changes to this bug.

Attachment

General

Created:
Updated:
Size: