<commit_before>from __future__ import absolute_import

from functools import partial

from graphene import relay
from graphene.relay.connection import PageInfo
from graphql_relay.connection.connectiontypes import Edge

from graphene_pynamodb.utils import get_key_name


class PynamoConnectionField(relay.ConnectionField):
    def __init__(self, type, *args, **kwargs):
        super(PynamoConnectionField, self).__init__(
            type,
            *args,
            **kwargs
        )

    @property
    def model(self):
        return self.type._meta.node._meta.model

    @classmethod
    def get_query(cls, model, context, info, args):
        return model.scan

    @classmethod
    def connection_resolver(cls, resolver, connection, model, root, args, context, info):
        iterable = resolver(root, args, context, info)

        first = args.get('first')
        after = args.get('after')
        last = args.get('last')
        before = args.get('before')
        has_previous_page = bool(after)
        page_size = first if first else last if last else None
        connection_type = connection
        pageinfo_type = PageInfo

        # get a full scan query since we have no resolved iterable from relationship or resolver function
        if not iterable and not root:
            query = cls.get_query(model, context, info, args)
            iterable = query()
            if first or last or after or before:
                raise NotImplementedError(
                    "DynamoDB scan operations have no predictable sort. Arguments first, last, after " +
                    "and before will have unpredictable results")

        iterable = iterable if isinstance(iterable, list) else list([])

        if last:
            iterable = iterable[-last:]

        (has_next, edges) = cls.get_edges_from_iterable(iterable, model, edge_type=connection.Edge, after=after,
                                                        page_size=page_size)

        key_name = get_key_name(model)
        try:
            start_cursor = getattr(edges[0].node, key_name)
            end_cursor = getattr(edges[-1].node, key_name)
        except IndexError:
            start_cursor = None
            end_cursor = None

        # Construct the connection
        return connection_type(
            edges=edges,
            page_info=pageinfo_type(
                start_cursor=start_cursor if start_cursor else '',<commit_msg>Another bug caught by tests<commit_after>from __future__ import absolute_import

from functools import partial

from graphene import relay
from graphene.relay.connection import PageInfo
from graphql_relay.connection.connectiontypes import Edge

from graphene_pynamodb.utils import get_key_name


class PynamoConnectionField(relay.ConnectionField):
    def __init__(self, type, *args, **kwargs):
        super(PynamoConnectionField, self).__init__(
            type,
            *args,
            **kwargs
        )

    @property
    def model(self):
        return self.type._meta.node._meta.model

    @classmethod
    def get_query(cls, model, context, info, args):
        return model.scan

    @classmethod
    def connection_resolver(cls, resolver, connection, model, root, args, context, info):
        iterable = resolver(root, args, context, info)

        first = args.get('first')
        after = args.get('after')
        last = args.get('last')
        before = args.get('before')
        has_previous_page = bool(after)
        page_size = first if first else last if last else None
        connection_type = connection
        pageinfo_type = PageInfo

        # get a full scan query since we have no resolved iterable from relationship or resolver function
        if not iterable and not root:
            query = cls.get_query(model, context, info, args)
            iterable = query()
            if first or last or after or before:
                raise NotImplementedError(
                    "DynamoDB scan operations have no predictable sort. Arguments first, last, after " +
                    "and before will have unpredictable results")

        iterable = iterable if isinstance(iterable, list) else list(iterable) if iterable else []
        if last:
            iterable = iterable[-last:]

        (has_next, edges) = cls.get_edges_from_iterable(iterable, model, edge_type=connection.Edge, after=after,
                                                        page_size=page_size)

        key_name = get_key_name(model)
        try:
            start_cursor = getattr(edges[0].node, key_name)
            end_cursor = getattr(edges[-1].node, key_name)
        except IndexError:
            start_cursor = None
            end_cursor = None

        # Construct the connection
        return connection_type(
            edges=edges,
            page_info=pageinfo_type(
                start_cursor=start_cursor if start_cursor else '',
{'fraction_non_alphanumeric': 0.07374210633530251, 'fraction_numerical': 0.0008148299042574863, 'mean_word_length': 2.260292164674635, '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': 4, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7191585', 'n_tokens_mistral': 1314, 'n_tokens_neox': 1265, 'n_words': 385}