<commit_before># -*- coding: utf-8 -*-
from __future__ import unicode_literals
from uuid import uuid4

from django.db import migrations, models
from profiles.util import make_thumbnail


def populate_image_small(apps, schema_editor):
    """
    Populate image_small with thumbnail of image if it exists
    """
    Profile = apps.get_model('profiles.Profile')
    for profile in Profile.objects.all():
        if profile.image and not profile.image_small:
            thumbnail = make_thumbnail(profile.image.file)
            profile.image_small.save("{}.jpg".format(uuid4().hex), thumbnail)


class Migration(migrations.Migration):

    dependencies = [
        ('profiles', '0024_add_image_small'),
    ]

    operations = [
        migrations.RunPython(populate_image_small, reverse_code=lambda apps, schema_editor: None),
    ]<commit_msg>Check for OSError during image migration (#2217)<commit_after># -*- coding: utf-8 -*-
from __future__ import unicode_literals
from uuid import uuid4

from django.db import migrations, models
from profiles.util import make_thumbnail


def populate_image_small(apps, schema_editor):
    """
    Populate image_small with thumbnail of image if it exists
    """
    Profile = apps.get_model('profiles.Profile')
    for profile in Profile.objects.all():
        if profile.image and not profile.image_small:
            try:
                thumbnail = make_thumbnail(profile.image.file)
                profile.image_small.save("{}.jpg".format(uuid4().hex), thumbnail)
            except OSError:
                pass


class Migration(migrations.Migration):

    dependencies = [
        ('profiles', '0024_add_image_small'),
    ]

    operations = [
        migrations.RunPython(populate_image_small, reverse_code=lambda apps, schema_editor: None),
    ]
{'fraction_non_alphanumeric': 0.09949972206781545, 'fraction_numerical': 0.010005558643690939, 'mean_word_length': 3.25531914893617, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1782922', 'n_tokens_mistral': 528, 'n_tokens_neox': 509, 'n_words': 126}