Commit 6c1181c7 by Matt Drayer Committed by Jonathan Piacenti

mattdrayer/api-migration-logging: Added logging to script exceptions

parent 96eef439
""" """
One-time data migration script -- shoulen't need to run it again One-time data migration script -- shoulen't need to run it again
""" """
import logging
from django.contrib.auth.models import User from django.contrib.auth.models import User
from django.core.management.base import BaseCommand from django.core.management.base import BaseCommand
from django.test import RequestFactory from django.test import RequestFactory
...@@ -9,6 +11,8 @@ from api_manager import models as api_models ...@@ -9,6 +11,8 @@ from api_manager import models as api_models
from api_manager.courseware_access import get_course, get_course_child from api_manager.courseware_access import get_course, get_course_child
from opaque_keys import InvalidKeyError from opaque_keys import InvalidKeyError
log = logging.getLogger(__name__)
class Command(BaseCommand): class Command(BaseCommand):
""" """
...@@ -35,6 +39,10 @@ class Command(BaseCommand): ...@@ -35,6 +39,10 @@ class Command(BaseCommand):
try: try:
ccg.content_id = course_key.make_usage_key_from_deprecated_string(ccg.content_id) ccg.content_id = course_key.make_usage_key_from_deprecated_string(ccg.content_id)
except InvalidKeyError: except InvalidKeyError:
log.warning(
'Unable to convert content_id "{}"'.format(ccg.content_id),
exc_info=True
)
pass # If the key conversion fails it was either a new-style key or junk data pass # If the key conversion fails it was either a new-style key or junk data
ccg.save() ccg.save()
...@@ -46,5 +54,9 @@ class Command(BaseCommand): ...@@ -46,5 +54,9 @@ class Command(BaseCommand):
try: try:
cmc.content_id = course_key.make_usage_key_from_deprecated_string(cmc.content_id) cmc.content_id = course_key.make_usage_key_from_deprecated_string(cmc.content_id)
except InvalidKeyError: except InvalidKeyError:
log.warning(
'Unable to convert content_id "{}"'.format(cmc.content_id),
exc_info=True
)
pass # If the key conversion fails it was either a new-style key or junk data pass # If the key conversion fails it was either a new-style key or junk data
cmc.save() cmc.save()
""" """
One-time data migration script -- shoulen't need to run it again One-time data migration script -- shoulen't need to run it again
""" """
import logging
from django.contrib.auth.models import User from django.contrib.auth.models import User
from django.core.management.base import BaseCommand from django.core.management.base import BaseCommand
from django.test import RequestFactory from django.test import RequestFactory
...@@ -9,6 +11,7 @@ from api_manager.courseware_access import get_course, get_course_child ...@@ -9,6 +11,7 @@ from api_manager.courseware_access import get_course, get_course_child
from opaque_keys import InvalidKeyError from opaque_keys import InvalidKeyError
from project.models import Project, WorkgroupReview, WorkgroupSubmissionReview from project.models import Project, WorkgroupReview, WorkgroupSubmissionReview
log = logging.getLogger(__name__)
class Command(BaseCommand): class Command(BaseCommand):
""" """
...@@ -27,6 +30,10 @@ class Command(BaseCommand): ...@@ -27,6 +30,10 @@ class Command(BaseCommand):
try: try:
project.content_id = course_key.make_usage_key_from_deprecated_string(project.content_id) project.content_id = course_key.make_usage_key_from_deprecated_string(project.content_id)
except InvalidKeyError: except InvalidKeyError:
log.warning(
'Unable to convert content_id "{}"'.format(project.content_id),
exc_info=True
)
pass # If the key conversion fails it was either a new-style key or junk data pass # If the key conversion fails it was either a new-style key or junk data
project.save() project.save()
...@@ -37,6 +44,10 @@ class Command(BaseCommand): ...@@ -37,6 +44,10 @@ class Command(BaseCommand):
try: try:
wr.content_id = course_key.make_usage_key_from_deprecated_string(wr.content_id) wr.content_id = course_key.make_usage_key_from_deprecated_string(wr.content_id)
except InvalidKeyError: except InvalidKeyError:
log.warning(
'Unable to convert content_id "{}"'.format(wr.content_id),
exc_info=True
)
pass # If the key conversion fails it was either a new-style key or junk data pass # If the key conversion fails it was either a new-style key or junk data
wr.save() wr.save()
...@@ -47,5 +58,9 @@ class Command(BaseCommand): ...@@ -47,5 +58,9 @@ class Command(BaseCommand):
try: try:
wsr.content_id = course_key.make_usage_key_from_deprecated_string(wsr.content_id) wsr.content_id = course_key.make_usage_key_from_deprecated_string(wsr.content_id)
except InvalidKeyError: except InvalidKeyError:
log.warning(
'Unable to convert content_id "{}"'.format(wsr.content_id),
exc_info=True
)
pass # If the key conversion fails it was either a new-style key or junk data pass # If the key conversion fails it was either a new-style key or junk data
wsr.save() wsr.save()
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment