<commit_before>from rest_framework import serializers


class TaskSerializer(serializers.Serializer):
    id = serializers.UUIDField(source='uuid', read_only=True)
    uuid = serializers.UUIDField(read_only=True)
    short_id = serializers.IntegerField(source='id', read_only=True)
    status = serializers.CharField(required=False)
    urgency = serializers.FloatField(read_only=True)
    description = serializers.CharField(required=True)
    priority = serializers.CharField(required=False, allow_blank=True)
    project = serializers.CharField(required=False, allow_blank=True)
    due = serializers.DateTimeField(required=False)
    entry = serializers.DateTimeField(read_only=True)
    modified = serializers.DateTimeField(read_only=True)
    start = serializers.DateTimeField(required=False)
    wait = serializers.DateTimeField(required=False)
    until = serializers.DateTimeField(required=False)
    scheduled = serializers.DateTimeField(required=False)
    depends = serializers.ListField(
        child=serializers.UUIDField(),
        required=False,
    )
    blocks = serializers.SerializerMethodField()
    annotations = serializers.ListField(
        child=serializers.CharField(),
        required=False,
    )
    tags = serializers.ListField(child=serializers.CharField(), required=False)
    imask = serializers.CharField(read_only=True)
    udas = serializers.SerializerMethodField()

    def __init__(self, *args, **kwargs):
        self._store = kwargs.pop('store')
        super(TaskSerializer, self).__init__(*args, **kwargs)

    @property
    def store(self):
        return self._store

    def get_udas(self, obj):
        udas = {}
        for field in self.store.client.config.get_udas().keys():
            if field in obj:
                udas[field] = obj[field]

        return udas

    def get_blocks(self, obj):
        return self.store.get_blocks_for_task(obj)

    def update(self, store, pk, data):
        original = store.client.get_task(uuid=pk)[1]
        for k, v in data.items():
            if k == 'priority' and v == '':
                v = None
            original[k] = v

        changes = original.get_changes(keep=True)
        store.client.task_update(original)

        return original, changes

    def create(self, store, data):
        for k, v in data.items():
            if not v:
                data.pop(k, None)

        return store.client.task_add(**data)<commit_msg>[INTHEAM-AK] Fix bug in dict iteration when creating new tasks.<commit_after>from rest_framework import serializers


class TaskSerializer(serializers.Serializer):
    id = serializers.UUIDField(source='uuid', read_only=True)
    uuid = serializers.UUIDField(read_only=True)
    short_id = serializers.IntegerField(source='id', read_only=True)
    status = serializers.CharField(required=False)
    urgency = serializers.FloatField(read_only=True)
    description = serializers.CharField(required=True)
    priority = serializers.CharField(required=False, allow_blank=True)
    project = serializers.CharField(required=False, allow_blank=True)
    due = serializers.DateTimeField(required=False)
    entry = serializers.DateTimeField(read_only=True)
    modified = serializers.DateTimeField(read_only=True)
    start = serializers.DateTimeField(required=False)
    wait = serializers.DateTimeField(required=False)
    until = serializers.DateTimeField(required=False)
    scheduled = serializers.DateTimeField(required=False)
    depends = serializers.ListField(
        child=serializers.UUIDField(),
        required=False,
    )
    blocks = serializers.SerializerMethodField()
    annotations = serializers.ListField(
        child=serializers.CharField(),
        required=False,
    )
    tags = serializers.ListField(child=serializers.CharField(), required=False)
    imask = serializers.CharField(read_only=True)
    udas = serializers.SerializerMethodField()

    def __init__(self, *args, **kwargs):
        self._store = kwargs.pop('store')
        super(TaskSerializer, self).__init__(*args, **kwargs)

    @property
    def store(self):
        return self._store

    def get_udas(self, obj):
        udas = {}
        for field in self.store.client.config.get_udas().keys():
            if field in obj:
                udas[field] = obj[field]

        return udas

    def get_blocks(self, obj):
        return self.store.get_blocks_for_task(obj)

    def update(self, store, pk, data):
        original = store.client.get_task(uuid=pk)[1]
        for k, v in data.items():
            if k == 'priority' and v == '':
                v = None
            original[k] = v

        changes = original.get_changes(keep=True)
        store.client.task_update(original)

        return original, changes

    def create(self, store, data):
        record = {}

        for k, v in data.items():
            if v:
                record[k] = v

        return store.client.task_add(**record)
{'fraction_non_alphanumeric': 0.10771411216845515, 'fraction_numerical': 0.00040494027130998176, 'mean_word_length': 3.1338912133891212, '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': '3003485', 'n_tokens_mistral': 1439, 'n_tokens_neox': 1415, 'n_words': 278}