<commit_before>from flask.ext.sqlalchemy import BaseQuery
from sqlalchemy.sql import or_


class AccessQuery(BaseQuery):

    def _filter_for(self, class_, fltr):
        return class_.query.filter(or_(
                    *[x for x in filter(lambda x: x is not None, [
                        t(class_, fltr)
                        # weirdly class_.__access_filters fails on us
                        # probably some sqlalchemy magic
                        for t in getattr(class_, "__access_filters")[fltr]
                    ])]))

    def filter_visible(self, attr, remoteAttr):
        return self.filter(attr.in_(
            self._filter_for(remoteAttr.class_, 'view')
                .with_entities(remoteAttr)
                .subquery()
            )
        )
<commit_msg>Improved Access Query: returns nothing if no filter is found<commit_after>from flask.ext.sqlalchemy import BaseQuery
from sqlalchemy.sql import or_


class AccessQuery(BaseQuery):

    def _gen_filters(self, class_, fltr):
        return [x for x in filter(lambda x: x is not None, [
            t(class_, fltr)
            # weirdly class_.__access_filters fails on us
            # probably some sqlalchemy magic
            for t in getattr(class_, "__access_filters")[fltr]]
            )
        ]

    def filter_visible(self, attr, remoteAttr):
        filters = self._gen_filters(remoteAttr.class_, 'view')
        if not filters:
            return self.filter(False)

        return self.filter(attr.in_(
            remoteAttr.class_.query.filter(or_(*filters))
                             .with_entities(remoteAttr)
                             .subquery()
            )
        )

{'fraction_non_alphanumeric': 0.0826888756692445, 'fraction_numerical': 0.0, 'mean_word_length': 1.7893864013266998, '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': '2201012', 'n_tokens_mistral': 466, 'n_tokens_neox': 445, 'n_words': 119}