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

Python error in Index suggestion widget #10

Closed
Marczeeee opened this issue Nov 29, 2015 · 3 comments
Closed

Python error in Index suggestion widget #10

Marczeeee opened this issue Nov 29, 2015 · 3 comments
Assignees
Labels

Comments

@Marczeeee
Copy link

I installed Powa (3.0.0) with Powa-web, but when I open Query detail page sometimes (but not always) the Index suggestion widget doesn't load properly and the "An error occured while loading this widget" text displayed instead. On the console the following Python error is shown:

    Traceback (most recent call last):
      File "/usr/lib/python2.7/dist-packages/tornado/web.py", line 1141, in _when_complete
        callback()
      File "/usr/lib/python2.7/dist-packages/tornado/web.py", line 1162, in _execute_method
        self._when_complete(method(*self.path_args, **self.path_kwargs),
      File "/home/jpasztor/powa-web-3.0.0/powa/query.py", line 205, in get
        hypoplan=hypoplan)
      File "/usr/lib/python2.7/dist-packages/tornado/web.py", line 538, in render
        html = self.render_string(template_name, **kwargs)
      File "/usr/lib/python2.7/dist-packages/tornado/web.py", line 645, in render_string
        return t.generate(**namespace)
      File "/usr/lib/python2.7/dist-packages/tornado/template.py", line 273, 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 "/home/user/powa-web-3.0.0/powa/sql/__init__.py", line 139, in distinct_values
        return "%s %%" % (abs(self.n_distinct) * 100)
    TypeError: bad operand type for abs(): 'NoneType'
@rjuju
Copy link
Member

rjuju commented Nov 29, 2015

It looks like you have some columns which don't have an n_distinct entry.

What does the following query returns on the related database ?

SELECT n.nspname,c.relname, a.attname, t.typname, s.*
FROM pg_class c
JOIN pg_namespace n ON c.relnamespace = n.oid
JOIN pg_attribute a ON a.attrelid = c.oid
JOIN pg_type t ON a.atttypid = t.oid
LEFT JOIN pg_statistic s ON s.starelid = c.oid AND s.staattnum = a.attnum
WHERE s.stadistinct is NULL
AND nspname NOT IN ('information_schema','pg_catalog','pg_toast') AND attnum > 0;

As a quick workaround, an "ANALYZE tablename" for the tables involved in the index suggestion should resolve the issue, until we fix this case and release a new version of powa-web.

@Marczeeee
Copy link
Author

The given query returned a pretty long resultset (1020 entries). Using ANALYZE seems to solve the problem as after running it the error is gone (and the resultset of the query contains only 770 entries).
Thanks for your help!

@rjuju rjuju added the bug label Nov 30, 2015
@rjuju rjuju self-assigned this Nov 30, 2015
@rjuju
Copy link
Member

rjuju commented Nov 30, 2015

The commit 11725f5 should solve this issue. I recommend you to wait a new release of powa-web, because there's currently a new feature (adding tabs on the query page) being implemented and it's not finished yet.

Thanks.

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

No branches or pull requests

2 participants