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

Downloading the list of users from sysadmin/dashboard triggers a 500 error #358

Closed
regisb opened this issue Jul 21, 2020 · 1 comment
Closed
Labels
bug Bugs will be investigated and fixed as quickly as possible. upstream issue Upstream Open edX bugs will probably not be fixed by Tutor

Comments

@regisb
Copy link
Contributor

regisb commented Jul 21, 2020

Bug description

It's impossible to download the CSV list of users from the sysadmin dashboard.

How to reproduce

  1. Go to http://local.overhang.io:8000/sysadmin/
  2. Click "download list of all users (csv file)"
  3. A 500 error is generated.

Here are the logs from the LMS:

Internal Server Error: /sysadmin/                                                                                                                             
Traceback (most recent call last):                                                                                                                            
  File "/openedx/venv/lib/python3.5/site-packages/django/core/handlers/exception.py", line 34, in inner                                                       
    response = get_response(request)                                                                                                                          
  File "/openedx/venv/lib/python3.5/site-packages/django/core/handlers/base.py", line 115, in _get_response                                                   
    response = self.process_exception_by_middleware(e, request)                                                                                               
  File "/openedx/venv/lib/python3.5/site-packages/django/core/handlers/base.py", line 113, in _get_response                                                   
    response = wrapped_callback(request, *callback_args, **callback_kwargs)                                                                                   
  File "/opt/pyenv/versions/3.5.9/lib/python3.5/contextlib.py", line 30, in inner                                                                             
    return func(*args, **kwds)                                                                                                                                
  File "/openedx/venv/lib/python3.5/site-packages/django/views/generic/base.py", line 71, in view                                                             
    return self.dispatch(request, *args, **kwargs)                                                                                                            
  File "/openedx/venv/lib/python3.5/site-packages/django/utils/decorators.py", line 45, in _wrapper                                                           
    return bound_method(*args, **kwargs)                                                                                                                      
  File "/openedx/venv/lib/python3.5/site-packages/django/utils/decorators.py", line 142, in _wrapped_view                                                     
    response = view_func(request, *args, **kwargs)                                                                                                            
  File "/openedx/venv/lib/python3.5/site-packages/django/utils/decorators.py", line 45, in _wrapper                                                           
    return bound_method(*args, **kwargs)                                                                                                                      
  File "/openedx/venv/lib/python3.5/site-packages/django/contrib/auth/decorators.py", line 21, in _wrapped_view                                               
    return view_func(request, *args, **kwargs)                                                                                                                
  File "/openedx/venv/lib/python3.5/site-packages/django/utils/decorators.py", line 45, in _wrapper                                                           
    return bound_method(*args, **kwargs)                                                                                                                      
  File "/openedx/venv/lib/python3.5/site-packages/django/views/decorators/cache.py", line 31, in _cache_controlled                                            
    response = viewfunc(request, *args, **kw)                                                                                                                 
  File "/openedx/venv/lib/python3.5/site-packages/django/utils/decorators.py", line 45, in _wrapper                                                           
    return bound_method(*args, **kwargs)                                                                                                                      
  File "/openedx/venv/lib/python3.5/site-packages/django/views/decorators/http.py", line 99, in inner
    response = func(request, *args, **kwargs)
  File "/openedx/edx-platform/lms/djangoapps/dashboard/sysadmin.py", line 67, in dispatch
    return super(SysadminDashboardView, self).dispatch(*args, **kwargs)
  File "/openedx/venv/lib/python3.5/site-packages/django/views/generic/base.py", line 97, in dispatch
    return handler(request, *args, **kwargs)
  File "/openedx/edx-platform/lms/djangoapps/dashboard/sysadmin.py", line 219, in post
    request.META['SERVER_NAME']), header, data)
  File "/openedx/edx-platform/lms/djangoapps/dashboard/sysadmin.py", line 84, in return_csv
    writer.writerow(header)
  File "/openedx/venv/lib/python3.5/site-packages/unicodecsv/py3.py", line 28, in writerow
    return self.writer.writerow(row)
  File "/openedx/venv/lib/python3.5/site-packages/unicodecsv/py3.py", line 15, in write
    return self.binary.write(string.encode(self.encoding, self.errors))
TypeError: string argument expected, got 'bytes'

This is a minimal piece of code that reproduces the error:

from six import StringIO
import unicodecsv as csv
writer = csv.writer(csv_file, dialect='excel', quotechar='"', quoting=csv.QUOTE_ALL)
writer.writerow(["username", "email"])

This piece of code can be fixed by replacing the "unicodecsv" library, which was made for python 2, by the standard csv library:

from six import StringIO
import csv
writer = csv.writer(csv_file, dialect='excel', quotechar='"', quoting=csv.QUOTE_ALL)
writer.writerow(["username", "email"])

This is an upstream issue with edx-platform. We should address this issue by replacing unicodecsv by csv pretty much everywhere. We should also add some unit tests to make sure there is no regression.

Environment

➭ tutor --version
tutor, version 10.0.11

Additional context

See conversation: https://discuss.overhang.io/t/tutor-10-0-11-sysadmin-feature-generates-500-error/776

@regisb regisb added bug Bugs will be investigated and fixed as quickly as possible. upstream issue Upstream Open edX bugs will probably not be fixed by Tutor labels Jul 21, 2020
@regisb
Copy link
Contributor Author

regisb commented Jul 24, 2020

Closing this as the sysadmin dashboard is slated for deprecation https://app.slack.com/client/T02SNA1T6/CK94QNCQ0

@regisb regisb closed this as completed Jul 24, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Bugs will be investigated and fixed as quickly as possible. upstream issue Upstream Open edX bugs will probably not be fixed by Tutor
Projects
None yet
Development

No branches or pull requests

1 participant