<commit_before># coding: utf-8
import json

from django.db.models.expressions import Func


class ReplaceValues(Func):
    """
    Updates several properties at once of a JSONBField without overwriting the
    whole document.
    Avoids race conditions when document is saved in two different transactions
    at the same time. (i.e.: `Asset._deployment['status']`)

    https://www.postgresql.org/docs/current/functions-json.html
    """
    function = 'jsonb_set'
    template = "%(expressions)s || '%(updates)s'"
    arity = 1

    def __init__(
        self,
        expression: str,
        updates: dict,
        **extra,
    ):
        super().__init__(
            expression,
            updates=json.dumps(updates),
            **extra,
        )<commit_msg>Fixed: Cannot update _deployment_data with single quote<commit_after># coding: utf-8
import json


from django.db.models.expressions import Func, Value


class ReplaceValues(Func):
    """
    Updates several properties at once of a JSONBField without overwriting the
    whole document.
    Avoids race conditions when document is saved in two different transactions
    at the same time. (i.e.: `Asset._deployment['status']`)
    https://www.postgresql.org/docs/current/functions-json.html

    Notes from postgres docs:
    > Does not operate recursively: only the top-level array or object
    > structure is merged
    """
    arg_joiner = ' || '
    template = "%(expressions)s"
    arity = 2

    def __init__(
        self,
        expression: str,
        updates: dict,
        **extra,
    ):
        super().__init__(
            expression,
            Value(json.dumps(updates)),
            **extra,
        )
{'fraction_non_alphanumeric': 0.10106382978723404, 'fraction_numerical': 0.002364066193853428, 'mean_word_length': 2.4480651731160896, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 5, 'https://': 2, 'lorem ipsum': 0, 'www.': 2, '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': '6588224', 'n_tokens_mistral': 487, 'n_tokens_neox': 475, 'n_words': 145}