<commit_before>from sqlalchemy.orm.util import class_mapper

from ..extensions import db

def _is_sql_wrapper(instance):
    """Determines if instance is a SQLAlchemy wrapper (ORM instance)"""
    try:
        class_mapper(instance.__class__)
        return True
    except:
        return False


def lazyprop(fn):
    """Property decorator for lazy intialization (load on first request)

    Useful on any expensive to load attribute on any class.  Simply
    decorate the 'getter' with @lazyprop, where the function definition
    loads the object to be assigned to the given attribute.

    """
    attr_name = '_lazy_{}'.format(fn.__name__)
    @property
    def _lazyprop(self):
        if not hasattr(self, attr_name):
            setattr(self, attr_name, fn(self))

        attr = getattr(self, attr_name)

        # ORM objects (especially in testing) are occasionally detached
        if _is_sql_wrapper(attr):<commit_msg>Disable cache till we make it thread safe<commit_after>from sqlalchemy.orm.util import class_mapper

from ..extensions import db

def _is_sql_wrapper(instance):
    """Determines if instance is a SQLAlchemy wrapper (ORM instance)"""
    try:
        class_mapper(instance.__class__)
        return True
    except:
        return False


def lazyprop(fn):
    """Property decorator for lazy intialization (load on first request)

    Useful on any expensive to load attribute on any class.  Simply
    decorate the 'getter' with @lazyprop, where the function definition
    loads the object to be assigned to the given attribute.

    """
    attr_name = '_lazy_{}'.format(fn.__name__)
    disable_cache = True
    @property
    def _lazyprop(self):
        if disable_cache:
            return fn(self)

        if not hasattr(self, attr_name):
            setattr(self, attr_name, fn(self))

        attr = getattr(self, attr_name)

        # ORM objects (especially in testing) are occasionally detached
        if _is_sql_wrapper(attr):
{'fraction_non_alphanumeric': 0.07606490872210954, 'fraction_numerical': 0.0, 'mean_word_length': 3.026530612244898, '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': '881286', 'n_tokens_mistral': 568, 'n_tokens_neox': 552, 'n_words': 196}