powa-team / powa

PostgreSQL Workload Analyzer
http://powa.readthedocs.io/
PostgreSQL License
764 stars 57 forks source link

Unable to view index suggestions - TypeError: bad operand type for abs(): 'NoneType' #61

Closed ribbles closed 8 years ago

ribbles commented 8 years ago

Unable to view index suggestions. Instead I see an error on the UI element and the following error in the logs:

[E 151215 01:36:45 web:1496] Uncaught exception GET /metrics/database/my_db/query/4060808085/indexes?from=2015-12-14+16%3A37%3A14-0800&to=2015-12-14+17%3A37%3A14-0800 (127.0.0.1)
    HTTPServerRequest(...)
    Traceback (most recent call last):
      File "/usr/lib/python2.7/dist-packages/tornado/web.py", line 1413, in _execute
        result = method(*self.path_args, **self.path_kwargs)
      File "/usr/local/lib/python2.7/dist-packages/powa/query.py", line 205, in get
        hypoplan=hypoplan)
      File "/usr/lib/python2.7/dist-packages/tornado/web.py", line 704, in render
        html = self.render_string(template_name, **kwargs)
      File "/usr/lib/python2.7/dist-packages/tornado/web.py", line 811, in render_string
        return t.generate(**namespace)
      File "/usr/lib/python2.7/dist-packages/tornado/template.py", line 278, in generate
        return execute()
      File "database/query/indexes_html.generated.py", line 43, in _tt_execute
        _tt_tmp = qual.distinct_values  # database/query/indexes.html:24 (via xhr.html:4)
      File "/usr/local/lib/python2.7/dist-packages/powa/sql/__init__.py", line 139, in distinct_values
        return "%s %%" % (abs(self.n_distinct) * 100)
    TypeError: bad operand type for abs(): 'NoneType'

Editing /powa/sql/init.py line 136 wrapping the code in try/catch gets past the issue (hack):

    @property
    def distinct_values(self):
        try:
                if self.n_distinct > 0:
                    return "%s" % self.n_distinct
                else:
                    return "%s %%" % (abs(self.n_distinct) * 100)
        except TypeError:
                pass
        return "0"
rjuju commented 8 years ago

Hello,

Thanks for the report. This issue has already been reported (see https://github.com/dalibo/powa-web/issues/10), and fixed in commit https://github.com/dalibo/powa-web/commit/11725f5518e42d07b0245524556d19d0587cc0f9.

Before the next version of powa-web is released, a quick workaround is to perform an ANALYZE on the related tables.