Skip to content

Commit

Permalink
Update exception handling to be compatible with py3
Browse files Browse the repository at this point in the history
  • Loading branch information
dodobas committed Mar 5, 2018
1 parent 10cd220 commit aa61f84
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 5 deletions.
5 changes: 3 additions & 2 deletions smartmin/csv_imports/tasks.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
from __future__ import unicode_literals

import six
from celery.task import task
from django.db import transaction
from django.utils import timezone
Expand Down Expand Up @@ -37,11 +38,11 @@ def csv_import(task_id): # pragma: no cover

except Exception as e:
import traceback
traceback.print_exc(e)
traceback.print_exc()

task_obj.task_status = ImportTask.FAILURE

task_obj.log("\nError: %s\n" % e)
task_obj.log("\nError: %s\n" % six.text_type(e))
task_obj.log(log.getvalue())
task_obj.save()

Expand Down
4 changes: 2 additions & 2 deletions smartmin/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -355,12 +355,12 @@ def unicode_csv_reader(utf8_data, dialect=csv.excel, **kwargs):
num_errors += 1

except SmartImportRowError as e:
error_messages.append(dict(line=line_number, error=str(e)))
error_messages.append(dict(line=line_number, error=six.text_type(e)))

except Exception as e:
if log:
traceback.print_exc(100, log)
raise Exception("Line %d: %s\n\n%s" % (line_number, str(e), field_values))
raise Exception("Line %d: %s\n\n%s" % (line_number, six.text_type(e), field_values))

if import_results is not None:
import_results['records'] = len(records)
Expand Down
2 changes: 1 addition & 1 deletion smartmin/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -1095,7 +1095,7 @@ def form_valid(self, form):
return response

except IntegrityError as e:
message = str(e).capitalize()
message = six.text_type(e).capitalize()
errors = self.form._errors.setdefault(forms.forms.NON_FIELD_ERRORS, forms.utils.ErrorList())
errors.append(message)
return self.render_to_response(self.get_context_data(form=form))
Expand Down

0 comments on commit aa61f84

Please sign in to comment.