Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

HTML report is not being generated (TypeError: must be str, not bytes) #38

Open
Daniel-Brosnan-Blazquez opened this issue Jul 9, 2018 · 0 comments

Comments

@Daniel-Brosnan-Blazquez
Copy link

Daniel-Brosnan-Blazquez commented Jul 9, 2018

When generating the report as html the following error occurs:
Traceback (most recent call last):
File "test_ingestion_xmls.py", line 1564, in
sqltap.report(statistics, "report.html", report_format="html")
File "/usr/local/lib/python3.4/dist-packages/sqltap/sqltap.py", line 534, in report
result = reporter.report()
File "/usr/local/lib/python3.4/dist-packages/sqltap/sqltap.py", line 381, in report
f.write(content)
TypeError: must be str, not bytes

Casting content as str makes visible the error:
KeyError: 'ingestion_duration'
/usr/local/lib/python3.4/dist-packages/sqltap/templates/html.mako, line 145:

                % for idx, query in enumerate(reversed(group.queries)):
                <tr class="${'hidden' if idx >= 3 else ''}">
                    <td>${'%.3f' % query.duration}</td>
                    % for param_name in params:
                    <td>${query.params[param_name]}</td> ## Here it seems to be the issue
                    % endfor
                    <td>${'%d' % query.rowcount}</td>
                    <td>${'%d' % query.params_id}</td>
                </tr>
                % endfor

This parameter is never used so I don't really understand why it is trying to use it.

Workaround to fix the issue

                % for idx, query in enumerate(reversed(group.queries)):
                <tr class="${'hidden' if idx >= 3 else ''}">
                    <td>${'%.3f' % query.duration}</td>
                    % for param_name in params:
                    % if param_name in query.params:  ## Enters only if key exists
                    <td>${query.params[param_name]}</td>
                    % endif
                    % endfor
                    <td>${'%d' % query.rowcount}</td>
                    <td>${'%d' % query.params_id}</td>
                </tr>
                % endfor

So, now it is accessing the parameters if they are available.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant