# -*- coding: utf-8 -*-
from __future__ import unicode_literals

from django.db import models, migrations


def rename_static_data_source_pillow_errors(apps, schema_editor):
    PillowError = apps.get_model("pillow_retry", "PillowError")
    old_name = 'corehq.apps.userreports.pillow.CustomDataSourcePillow'
    new_name = 'corehq.apps.userreports.pillow.StaticDataSourcePillow'
    for error_record in PillowError.objects.filter(pillow=old_name):
        error_record.pillow = new_name
        error_record.save()


class Migration(migrations.Migration):

    dependencies = [
        ('pillow_retry', '0002_pillowerror_queued'),
    ]

    operations = [
        migrations.RunPython(rename_static_data_source_pillow_errors)
    ]

@@ -98,16 +98,32 @@
 grations
+, IntegrityError
 %0A%0A%0Adef r
@@ -509,24 +509,106 @@
     
-error_record.sav
+try:%0A            error_record.save()%0A        except IntegrityError:%0A            error_record.delet
 e()%0A

delete old errors that have already been retried