<commit_before>"""
A custom manager for working with trees of objects.
"""
from __future__ import unicode_literals
import contextlib

from django.db import models, connections, router
from django.db.models import F, ManyToManyField, Max, Q
from django.utils.translation import ugettext as _

from mptt.exceptions import CantDisableUpdates, InvalidMove

__all__ = ('TreeManager',)


COUNT_SUBQUERY = """(
    SELECT COUNT(*)
    FROM %(rel_table)s
    WHERE %(mptt_fk)s = %(mptt_table)s.%(mptt_pk)s
)"""

CUMULATIVE_COUNT_SUBQUERY = """(
    SELECT COUNT(*)
    FROM %(rel_table)s
    WHERE %(mptt_fk)s IN
    (
        SELECT m2.%(mptt_pk)s
        FROM %(mptt_table)s m2<commit_msg>Get the related field name when it doesn't use a primary key for relation.<commit_after>"""
A custom manager for working with trees of objects.
"""
from __future__ import unicode_literals
import contextlib

from django.db import models, connections, router
from django.db.models import F, ManyToManyField, Max, Q
from django.utils.translation import ugettext as _

from mptt.exceptions import CantDisableUpdates, InvalidMove

__all__ = ('TreeManager',)


COUNT_SUBQUERY = """(
    SELECT COUNT(*)
    FROM %(rel_table)s
    WHERE %(mptt_fk)s = %(mptt_table)s.%(mptt_rel_to)s
)"""

CUMULATIVE_COUNT_SUBQUERY = """(
    SELECT COUNT(*)
    FROM %(rel_table)s
    WHERE %(mptt_fk)s IN
    (
        SELECT m2.%(mptt_rel_to)s
        FROM %(mptt_table)s m2
{'fraction_non_alphanumeric': 0.1073170731707317, 'fraction_numerical': 0.0027874564459930314, 'mean_word_length': 4.221818181818182, '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': '4354528', 'n_tokens_mistral': 528, 'n_tokens_neox': 496, 'n_words': 136}