Skip to content

Commit

Permalink
PLAT-1915 Stop using deprecated BaseException.message
Browse files Browse the repository at this point in the history
  • Loading branch information
jmbowman committed Jan 31, 2018
1 parent daaeb6b commit 5289c7e
Show file tree
Hide file tree
Showing 87 changed files with 255 additions and 180 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -61,4 +61,4 @@ def handle(self, *args, **options):
options.get('rdir', None)
)
except git_export_utils.GitExportError as ex:
raise CommandError(text_type(ex.message))
raise CommandError(text_type(ex))
3 changes: 2 additions & 1 deletion cms/djangoapps/contentstore/push_notification.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
from uuid import uuid4

from django.conf import settings
from six import text_type

from contentstore.models import PushNotificationConfig
from contentstore.tasks import push_course_update_task
Expand Down Expand Up @@ -80,4 +81,4 @@ def send_push_course_update(course_key_string, course_subscription_id, course_di
)

except ParseError as error:
log_exception(error.message)
log_exception(text_type(error))
5 changes: 3 additions & 2 deletions cms/djangoapps/contentstore/tests/test_transcripts_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
from django.utils import translation
from mock import Mock, patch
from nose.plugins.skip import SkipTest
from six import text_type

from contentstore.tests.utils import mock_requests_get
from xmodule.contentstore.content import StaticContent
Expand Down Expand Up @@ -425,7 +426,7 @@ def test_fail_bad_subs_type(self):

with self.assertRaises(transcripts_utils.TranscriptsGenerationException) as cm:
transcripts_utils.generate_subs_from_source(youtube_subs, 'BAD_FORMAT', srt_filedata, self.course)
exception_message = cm.exception.message
exception_message = text_type(cm.exception)
self.assertEqual(exception_message, "We support only SubRip (*.srt) transcripts format.")

def test_fail_bad_subs_filedata(self):
Expand All @@ -439,7 +440,7 @@ def test_fail_bad_subs_filedata(self):

with self.assertRaises(transcripts_utils.TranscriptsGenerationException) as cm:
transcripts_utils.generate_subs_from_source(youtube_subs, 'srt', srt_filedata, self.course)
exception_message = cm.exception.message
exception_message = text_type(cm.exception)
self.assertEqual(exception_message, "Something wrong with SubRip transcripts file during parsing.")


Expand Down
3 changes: 2 additions & 1 deletion cms/djangoapps/contentstore/views/assets.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
from django.views.decorators.http import require_POST, require_http_methods
from opaque_keys.edx.keys import AssetKey, CourseKey
from pymongo import ASCENDING, DESCENDING
from six import text_type
from xmodule.contentstore.content import StaticContent
from xmodule.contentstore.django import contentstore
from xmodule.exceptions import NotFoundError
Expand Down Expand Up @@ -402,7 +403,7 @@ def _upload_asset(request, course_key):
try:
content = update_course_run_asset(course_key, upload_file)
except AssetSizeTooLargeException as exception:
return JsonResponse({'error': exception.message}, status=413)
return JsonResponse({'error': text_type(exception)}, status=413)

# readback the saved content - we need the database timestamp
readback = contentstore().find(content.location)
Expand Down
5 changes: 3 additions & 2 deletions cms/djangoapps/contentstore/views/certificates.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
from django.views.decorators.http import require_http_methods
from opaque_keys import InvalidKeyError
from opaque_keys.edx.keys import AssetKey, CourseKey
from six import text_type

from contentstore.utils import get_lms_link_for_certificate_web_view, reverse_course_url
from contentstore.views.assets import delete_asset
Expand Down Expand Up @@ -423,7 +424,7 @@ def certificates_list_handler(request, course_key_string):
try:
new_certificate = CertificateManager.deserialize_certificate(course, request.body)
except CertificateValidationError as err:
return JsonResponse({"error": err.message}, status=400)
return JsonResponse({"error": text_type(err)}, status=400)
if course.certificates.get('certificates') is None:
course.certificates['certificates'] = []
course.certificates['certificates'].append(new_certificate.certificate_data)
Expand Down Expand Up @@ -480,7 +481,7 @@ def certificates_detail_handler(request, course_key_string, certificate_id):
try:
new_certificate = CertificateManager.deserialize_certificate(course, request.body)
except CertificateValidationError as err:
return JsonResponse({"error": err.message}, status=400)
return JsonResponse({"error": text_type(err)}, status=400)

serialized_certificate = CertificateManager.serialize_certificate(new_certificate)
cert_event_type = 'created'
Expand Down
19 changes: 10 additions & 9 deletions cms/djangoapps/contentstore/views/course.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
from opaque_keys.edx.locations import Location
from openedx.core.djangoapps.content.course_overviews.models import CourseOverview
from openedx.core.djangoapps.waffle_utils import WaffleSwitchNamespace
from six import text_type

from contentstore.course_group_config import (
COHORT_SCHEME,
Expand Down Expand Up @@ -812,7 +813,7 @@ def _create_or_rerun_course(request):
'course_key': unicode(new_course.id),
})
except ValidationError as ex:
return JsonResponse({'error': ex.message}, status=400)
return JsonResponse({'error': text_type(ex)}, status=400)
except DuplicateCourseError:
return JsonResponse({
'ErrMsg': _(
Expand All @@ -829,7 +830,7 @@ def _create_or_rerun_course(request):
})
except InvalidKeyError as error:
return JsonResponse({
"ErrMsg": _("Unable to create course '{name}'.\n\n{err}").format(name=display_name, err=error.message)}
"ErrMsg": _("Unable to create course '{name}'.\n\n{err}").format(name=display_name, err=text_type(error))}
)


Expand Down Expand Up @@ -1297,7 +1298,7 @@ def advanced_settings_handler(request, course_key_string):
# update the course tabs if required by any setting changes
_refresh_course_tabs(request, course_module)
except InvalidTabsException as err:
log.exception(err.message)
log.exception(text_type(err))
response_message = [
{
'message': _('An error occurred while trying to save your tabs'),
Expand All @@ -1316,7 +1317,7 @@ def advanced_settings_handler(request, course_key_string):
# Handle all errors that validation doesn't catch
except (TypeError, ValueError, InvalidTabsException) as err:
return HttpResponseBadRequest(
django.utils.html.escape(err.message),
django.utils.html.escape(text_type(err)),
content_type="text/plain"
)

Expand Down Expand Up @@ -1418,7 +1419,7 @@ def textbooks_list_handler(request, course_key_string):
try:
textbooks = validate_textbooks_json(request.body)
except TextbookValidationError as err:
return JsonResponse({"error": err.message}, status=400)
return JsonResponse({"error": text_type(err)}, status=400)

tids = set(t["id"] for t in textbooks if "id" in t)
for textbook in textbooks:
Expand All @@ -1437,7 +1438,7 @@ def textbooks_list_handler(request, course_key_string):
try:
textbook = validate_textbook_json(request.body)
except TextbookValidationError as err:
return JsonResponse({"error": err.message}, status=400)
return JsonResponse({"error": text_type(err)}, status=400)
if not textbook.get("id"):
tids = set(t["id"] for t in course.pdf_textbooks if "id" in t)
textbook["id"] = assign_textbook_id(textbook, tids)
Expand Down Expand Up @@ -1491,7 +1492,7 @@ def textbooks_detail_handler(request, course_key_string, textbook_id):
try:
new_textbook = validate_textbook_json(request.body)
except TextbookValidationError as err:
return JsonResponse({"error": err.message}, status=400)
return JsonResponse({"error": text_type(err)}, status=400)
new_textbook["id"] = textbook_id
if textbook:
i = course_module.pdf_textbooks.index(textbook)
Expand Down Expand Up @@ -1621,7 +1622,7 @@ def group_configurations_list_handler(request, course_key_string):
try:
new_configuration = GroupConfiguration(request.body, course).get_user_partition()
except GroupConfigurationsValidationError as err:
return JsonResponse({"error": err.message}, status=400)
return JsonResponse({"error": text_type(err)}, status=400)

course.user_partitions.append(new_configuration)
response = JsonResponse(new_configuration.to_json(), status=201)
Expand Down Expand Up @@ -1664,7 +1665,7 @@ def group_configurations_detail_handler(request, course_key_string, group_config
try:
new_configuration = GroupConfiguration(request.body, course, group_configuration_id).get_user_partition()
except GroupConfigurationsValidationError as err:
return JsonResponse({"error": err.message}, status=400)
return JsonResponse({"error": text_type(err)}, status=400)

if configuration:
index = course.user_partitions.index(configuration)
Expand Down
5 changes: 3 additions & 2 deletions cms/djangoapps/contentstore/views/item.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
from opaque_keys.edx.keys import CourseKey
from opaque_keys.edx.locator import LibraryUsageLocator
from pytz import UTC
from six import text_type
from web_fragments.fragment import Fragment
from xblock.core import XBlock
from xblock.fields import Scope
Expand Down Expand Up @@ -574,8 +575,8 @@ def _save_xblock(user, xblock, data=None, children_strings=None, metadata=None,
value = field.from_json(value)
except ValueError as verr:
reason = _("Invalid data")
if verr.message:
reason = _("Invalid data ({details})").format(details=verr.message)
if text_type(verr):
reason = _("Invalid data ({details})").format(details=text_type(verr))
return JsonResponse({"error": reason}, 400)

field.write_to(xblock, value)
Expand Down
5 changes: 3 additions & 2 deletions cms/djangoapps/contentstore/views/library.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
from opaque_keys import InvalidKeyError
from opaque_keys.edx.keys import CourseKey
from opaque_keys.edx.locator import LibraryLocator, LibraryUsageLocator
from six import text_type

from contentstore.utils import add_instructor, reverse_library_url
from contentstore.views.item import create_xblock_info
Expand Down Expand Up @@ -164,12 +165,12 @@ def _create_library(request):
except KeyError as error:
log.exception("Unable to create library - missing required JSON key.")
return JsonResponseBadRequest({
"ErrMsg": _("Unable to create library - missing required field '{field}'").format(field=error.message)
"ErrMsg": _("Unable to create library - missing required field '{field}'").format(field=text_type(error))
})
except InvalidKeyError as error:
log.exception("Unable to create library - invalid key.")
return JsonResponseBadRequest({
"ErrMsg": _("Unable to create library '{name}'.\n\n{err}").format(name=display_name, err=error.message)
"ErrMsg": _("Unable to create library '{name}'.\n\n{err}").format(name=display_name, err=text_type(error))
})
except DuplicateCourseError:
log.exception("Unable to create library - one already exists with the same key.")
Expand Down
13 changes: 7 additions & 6 deletions cms/djangoapps/contentstore/views/transcripts_ajax.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
from django.utils.translation import ugettext as _
from opaque_keys import InvalidKeyError
from opaque_keys.edx.keys import UsageKey
from six import text_type

from student.auth import has_course_author_access
from util.json_request import JsonResponse
Expand Down Expand Up @@ -133,7 +134,7 @@ def upload_transcripts(request):
response['subs'] = item.sub
response['status'] = 'Success'
except Exception as ex:
return error_response(response, ex.message)
return error_response(response, text_type(ex))
else:
return error_response(response, 'Empty video sources.')

Expand Down Expand Up @@ -242,7 +243,7 @@ def check_transcripts(request):
try:
__, videos, item = _validate_transcripts_data(request)
except TranscriptsRequestValidationException as e:
return error_response(transcripts_presence, e.message)
return error_response(transcripts_presence, text_type(e))

transcripts_presence['status'] = 'Success'

Expand Down Expand Up @@ -400,7 +401,7 @@ def choose_transcripts(request):
try:
data, videos, item = _validate_transcripts_data(request)
except TranscriptsRequestValidationException as e:
return error_response(response, e.message)
return error_response(response, text_type(e))

html5_id = data.get('html5_id') # html5_id chosen by user

Expand Down Expand Up @@ -433,7 +434,7 @@ def replace_transcripts(request):
try:
__, videos, item = _validate_transcripts_data(request)
except TranscriptsRequestValidationException as e:
return error_response(response, e.message)
return error_response(response, text_type(e))

youtube_id = videos['youtube']
if not youtube_id:
Expand All @@ -442,7 +443,7 @@ def replace_transcripts(request):
try:
download_youtube_subs(youtube_id, item, settings)
except GetTranscriptsFromYouTubeException as e:
return error_response(response, e.message)
return error_response(response, text_type(e))

item.sub = youtube_id
item.save_with_metadata(request.user)
Expand Down Expand Up @@ -504,7 +505,7 @@ def rename_transcripts(request):
try:
__, videos, item = _validate_transcripts_data(request)
except TranscriptsRequestValidationException as e:
return error_response(response, e.message)
return error_response(response, text_type(e))

old_name = item.sub

Expand Down
5 changes: 3 additions & 2 deletions cms/djangoapps/maintenance/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
from django.views.generic import View
from opaque_keys import InvalidKeyError
from opaque_keys.edx.keys import CourseKey
from six import text_type

from contentstore.management.commands.utils import get_course_versions
from edxmako.shortcuts import render_to_response
Expand Down Expand Up @@ -169,10 +170,10 @@ def post(self, request):
self.context['msg'] = COURSE_KEY_ERROR_MESSAGES['invalid_course_key']
except ItemNotFoundError as exc:
self.context['error'] = True
self.context['msg'] = exc.message
self.context['msg'] = text_type(exc)
except ValidationError as exc:
self.context['error'] = True
self.context['msg'] = exc.message
self.context['msg'] = text_type(exc)

if self.context['error']:
return self.render_response()
Expand Down
5 changes: 3 additions & 2 deletions cms/djangoapps/models/settings/course_metadata.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
"""
from django.conf import settings
from django.utils.translation import ugettext as _
from six import text_type
from xblock.fields import Scope

from xblock_django.models import XBlockStudioConfigurationFlag
Expand Down Expand Up @@ -176,7 +177,7 @@ def update_from_json(cls, descriptor, jsondict, user, filter_tabs=True):
key_values[key] = descriptor.fields[key].from_json(val)
except (TypeError, ValueError) as err:
raise ValueError(_("Incorrect format for field '{name}'. {detailed_message}").format(
name=model['display_name'], detailed_message=err.message))
name=model['display_name'], detailed_message=text_type(err)))

return cls.update_from_dict(key_values, descriptor, user)

Expand Down Expand Up @@ -211,7 +212,7 @@ def validate_and_update_from_json(cls, descriptor, jsondict, user, filter_tabs=T
key_values[key] = descriptor.fields[key].from_json(val)
except (TypeError, ValueError) as err:
did_validate = False
errors.append({'message': err.message, 'model': model})
errors.append({'message': text_type(err), 'model': model})

# If did validate, go ahead and update the metadata
if did_validate:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

from django.test import TestCase
from opaque_keys.edx.locations import CourseLocator
from six import text_type

from course_action_state.managers import CourseRerunUIStateManager
from course_action_state.models import CourseRerunState
Expand Down Expand Up @@ -103,7 +104,7 @@ def test_rerun_failed(self):
)
self.expected_rerun_state.pop('message')
rerun = self.verify_rerun_state()
self.assertIn(exception.message, rerun.message)
self.assertIn(text_type(exception), rerun.message)

# dismiss ui and verify
self.dismiss_ui_and_verify(rerun)
3 changes: 2 additions & 1 deletion common/djangoapps/django_comment_common/tests.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
from django.test import TestCase
from nose.plugins.attrib import attr
from opaque_keys.edx.locator import CourseLocator
from six import text_type

from django_comment_common.models import Role
from models import CourseDiscussionSettings
Expand Down Expand Up @@ -131,6 +132,6 @@ def test_invalid_data_types(self):
set_course_discussion_settings(self.course.id, **{field['name']: invalid_value})

self.assertEqual(
value_error.exception.message,
text_type(value_error.exception),
exception_msg_template.format(field['name'], field['type'].__name__)
)
9 changes: 5 additions & 4 deletions common/djangoapps/enrollment/data.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

from django.contrib.auth.models import User
from opaque_keys.edx.keys import CourseKey
from six import text_type

from enrollment.errors import (
CourseEnrollmentClosedError,
Expand Down Expand Up @@ -125,14 +126,14 @@ def create_course_enrollment(username, course_id, mode, is_active):
enrollment = CourseEnrollment.enroll(user, course_key, check_access=True)
return _update_enrollment(enrollment, is_active=is_active, mode=mode)
except NonExistentCourseError as err:
raise CourseNotFoundError(err.message)
raise CourseNotFoundError(text_type(err))
except EnrollmentClosedError as err:
raise CourseEnrollmentClosedError(err.message)
raise CourseEnrollmentClosedError(text_type(err))
except CourseFullError as err:
raise CourseEnrollmentFullError(err.message)
raise CourseEnrollmentFullError(text_type(err))
except AlreadyEnrolledError as err:
enrollment = get_course_enrollment(username, course_id)
raise CourseEnrollmentExistsError(err.message, enrollment)
raise CourseEnrollmentExistsError(text_type(err), enrollment)


def update_course_enrollment(username, course_id, mode=None, is_active=None):
Expand Down
Loading

0 comments on commit 5289c7e

Please sign in to comment.