# Buggy code
def get_user_roles(user=None):
    """
    Get all the roles associated with the user.

    :param user: the ab_user in FAB model.
    :return: a list of roles associated with the user.
    """
    if user is None:
        user = g.user
    if user.is_anonymous:
        public_role = current_app.appbuilder.config.get("AUTH_ROLE_PUBLIC")
        return (
            [current_app.appbuilder.security_manager.find_role(public_role)]
            if public_role
            else []
        )
    return user.roles


# Traceback (AttributeError)
-------------------------------------------------------------------------------
Node: 11af45a15833
-------------------------------------------------------------------------------
Traceback (most recent call last):
File "/home/airflow/.local/lib/python3.6/site-packages/flask/app.py", line 2446, in wsgi_app
response = self.full_dispatch_request()
File "/home/airflow/.local/lib/python3.6/site-packages/flask/app.py", line 1951, in full_dispatch_request
rv = self.handle_user_exception(e)
File "/home/airflow/.local/lib/python3.6/site-packages/flask/app.py", line 1820, in handle_user_exception
reraise(exc_type, exc_value, tb)
File "/home/airflow/.local/lib/python3.6/site-packages/flask/_compat.py", line 39, in reraise
raise value
File "/home/airflow/.local/lib/python3.6/site-packages/flask/app.py", line 1949, in full_dispatch_request
rv = self.dispatch_request()
File "/home/airflow/.local/lib/python3.6/site-packages/flask/app.py", line 1935, in dispatch_request
return self.view_functions[rule.endpoint](**req.view_args)
File "/home/airflow/.local/lib/python3.6/site-packages/flask_appbuilder/security/decorators.py", line 109, in wraps
return f(self, *args, **kwargs)
File "/home/airflow/.local/lib/python3.6/site-packages/flask_appbuilder/views.py", line 551, in list
widgets = self._list()
File "/home/airflow/.local/lib/python3.6/site-packages/flask_appbuilder/baseviews.py", line 1127, in _list
page_size=page_size,
File "/home/airflow/.local/lib/python3.6/site-packages/flask_appbuilder/baseviews.py", line 1026, in _get_list_widget
page_size=page_size,
File "/home/airflow/.local/lib/python3.6/site-packages/flask_appbuilder/models/sqla/interface.py", line 168, in query
query_count = self._get_base_query(query=query_count, filters=filters)
File "/home/airflow/.local/lib/python3.6/site-packages/flask_appbuilder/models/sqla/interface.py", line 85, in _get_base_query
query = filters.apply_all(query)
File "/home/airflow/.local/lib/python3.6/site-packages/flask_appbuilder/models/filters.py", line 269, in apply_all
query = flt.apply(query, value)
File "/home/airflow/.local/lib/python3.6/site-packages/airflow/www_rbac/views.py", line 2187, in apply
if appbuilder.sm.has_all_dags_access():
File "/home/airflow/.local/lib/python3.6/site-packages/airflow/www_rbac/security.py", line 320, in has_all_dags_access
self._has_role(['Admin', 'Viewer', 'Op', 'User']) or
File "/home/airflow/.local/lib/python3.6/site-packages/airflow/www_rbac/security.py", line 299, in _has_role
[r.name in role_name_or_list for r in self.get_user_roles()])
File "/home/airflow/.local/lib/python3.6/site-packages/airflow/www_rbac/security.py", line 229, in get_user_roles
public_role = appbuilder.config.get('AUTH_ROLE_PUBLIC')
AttributeError: 'NoneType' object has no attribute 'config'

# Fixed code
def get_user_roles(user=None):
    """
    Get all the roles associated with the user.

    :param user: the ab_user in FAB model.
    :return: a list of roles associated with the user.
    """
    if user is None:
        user = g.user
    if user.is_anonymous:
        public_role = current_app.appbuilder.get_app.config["AUTH_ROLE_PUBLIC"]
        return [current_app.appbuilder.sm.find_role(public_role)] if public_role else []
    return user.roles