AttributeError exception causing API 500 errors being experienced when searching Dashboards

Issue Summary

In some situations, when doing a search for dashboards is resulting in an AttributeError exception on obj.user.to_dict(). I have been unable to yet pinpoint any direct cause, only the process that leads up to the issue. In addition, the issue only manifests when searching, and only with some characters, not all. Primarily if there is a large number of results. If I just navigate through the pages on the Dashboards list, there is no issues experienced.

The order that I have been able to trace through the code, which leads to this problem is this:

  1. User types in search in the Dashboards page of Re:Dash
  2. DashboardListResource is called to search DB for dashboards the meets the query using models.Dashboard.search - Successful
  3. DashboardListResource orders the results of that query - Successful
  4. DashboardListResource calls serialize_dashboard as part of the pagination process for the the results of the order_results - Successful
  5. handlers.base.paginate paginates the results and passes it over to serialize_dashboards - Successful
  6. serialize_dashboard executes to serialize the paginated results to return - Fails ( items = [serializer(result) for result in results.items] fails with the exception AttributeError: 'NoneType' object has no attribute 'to_dict')

This issue appears to have started after we upgraded from Re:Dash 6.0.0 to 8.0.0. We used the normal DB upgrade scripts as part of the upgrade process.

This is the traceback being experienced:

[2020-04-14 12:10:05,461] ERROR in app: Exception on /api/dashboards [GET]
Traceback (most recent call last):
  File "/usr/local/lib/python2.7/site-packages/flask/app.py", line 1612, in full_dispatch_request
    rv = self.dispatch_request()
  File "/usr/local/lib/python2.7/site-packages/flask/app.py", line 1598, in dispatch_request
    return self.view_functions[rule.endpoint](**req.view_args)
  File "/usr/local/lib/python2.7/site-packages/flask_restful/__init__.py", line 477, in wrapper
    resp = resource(*args, **kwargs)
  File "/usr/local/lib/python2.7/site-packages/flask_login/utils.py", line 228, in decorated_view
    return func(*args, **kwargs)
  File "/usr/local/lib/python2.7/site-packages/flask/views.py", line 84, in view
    return self.dispatch_request(*args, **kwargs)
  File "/app/redash/handlers/base.py", line 31, in dispatch_request
    return super(BaseResource, self).dispatch_request(*args, **kwargs)
  File "/usr/local/lib/python2.7/site-packages/flask_restful/__init__.py\", line 587, in dispatch_request
    resp = meth(*args, **kwargs)
  File "/app/redash/permissions.py", line 67, in decorated
    return fn(*args, **kwargs)
  File "/app/redash/handlers/dashboards.py", line 76, in get
    serializer=serialize_dashboard,
  File "/app/redash/handlers/base.py", line 108, in paginate
    items = [serializer(result) for result in results.items]
  File "/app/redash/serializers/__init__.py", line 214, in serialize_dashboard
    'user': obj.user.to_dict(),
AttributeError: 'NoneType' object has no attribute 'to_dict'

Any assistance in identifying this issue would be greatly appreciated as this is greatly degrading the user’s ability to interact with Re:Dash.

Technical details:

  • Redash Version: 8.0.0+b32245
  • Browser/OS: Chrome (Running on Linux, impacts all users, regardless of OS)
  • How did you install Redash: Docker

How many users in your org? Do you get errors when you pull from the /api/users endpoint?

We have 1,535 users in the Org leveraging Re:Dash, and we don’t experience this issue anywhere but when searching Dashboards.

A little additional information. We have been able to replicate this in a lower environment. If we set the Page size to something small, and then do a search for a Dashboard, as soon as we click on the second page the exception is raised. Again, this only happens on Dashboards and only while searching. If you click through the pages on the Dashboard list without doing a search, the issue does not manifest.

Have you tried pulling from the /api/users endpoint?

Yes. It works without issue. The only place this issue has been experienced is the /api/dashboards. Upon digging deeper into the issue, we suspect there may be an issue in SQLAlchemy that might be getting triggered here.

The specific scenario we suspect is described here: https://github.com/sqlalchemy/sqlalchemy/issues/3650

We have found with Dashboard searches, that if the page size and the amount of entries being returned match, the issue doesn’t arise. It only arises when pagination attempts to break the results into multiple pages while searching for Dashboards. I was able to replicate the behavior in our lab environment by having 12 Dashboards with various content in them, set the page size to 5, do a search and click on other pages than the first one.

1 Like

Nice catch! Can you open an issue on Github for this?

Sure can! I’ll hope over there and do so now.

I have opened this issue for you: https://github.com/getredash/redash/issues/4803

1 Like