Skip to content

Issue module

Queries

Set of Issue queries.

Source code in kili/queries/issue/__init__.py
class QueriesIssue:
    """Set of Issue queries."""

    # pylint: disable=too-many-arguments,too-many-locals

    def __init__(self, auth):
        """Initialize the subclass.

        Args:
            auth: KiliAuth object
        """
        self.auth = auth

    # pylint: disable=dangerous-default-value
    @Compatible(['v1', 'v2'])
    @typechecked
    def issues(self,
               fields: Optional[List[str]] = [
                   'id',
                   'createdAt',
                   'hasBeenSeen',
                   'issueNumber',
                   'status',
                   'type'],
               first: Optional[int] = 100,
               project_id: Optional[str] = None,
               skip: Optional[int] = 0,
               disable_tqdm: bool = False,
               as_generator: bool = False) -> Union[List[dict], Generator[dict, None, None]]:
        # pylint: disable=line-too-long
        """Get a generator or a list of issues that match a set of criteria.

        Args:
            fields: All the fields to request among the possible fields for the assets.
                See [the documentation](https://docs.kili-technology.com/reference/graphql-api#issue) for all possible fields.
            first: Maximum number of issues to return.
            project_id: Project ID the issue belongs to.
            skip: Number of issues to skip (they are ordered by their date of creation, first to last).
            disable_tqdm: If `True`, the progress bar will be disabled
            as_generator: If `True`, a generator on the issues is returned.

        Returns:
            A result object which contains the query if it was successful,
                or an error message.

        Examples:
            >>> kili.issues(project_id=project_id, fields=['author.email']) # List all issues of a project and their authors
        """

        count_args = {'project_id': project_id}
        disable_tqdm = disable_tqdm or as_generator
        payload_query = {
            'where': {
                'project': {
                    'id': project_id,
                },
            },
        }

        issues_generator = row_generator_from_paginated_calls(
            skip,
            first,
            self.count_issues,
            count_args,
            self._query_issues,
            payload_query,
            fields,
            disable_tqdm
        )

        if as_generator:
            return issues_generator
        return list(issues_generator)

    def _query_issues(self,
                      skip: int,
                      first: int,
                      payload: dict,
                      fields: List[str]):
        payload.update({'skip': skip, 'first': first})
        _gql_issues = gql_issues(fragment_builder(fields, IssueType))
        result = self.auth.client.execute(_gql_issues, payload)
        return format_result('data', result)

    @Compatible(['v2'])
    @typechecked
    def count_issues(self, project_id: Optional[str] = None) -> int:
        """Count and return the number of api keys with the given constraints.

        Args:
            project_id: Project ID the issue belongs to.

        Returns:
            The number of issues with the parameters provided

        """
        variables = {
            'where': {
                'project': {
                    'id': project_id,
                },
            },
        }
        result = self.auth.client.execute(GQL_ISSUES_COUNT, variables)
        count = format_result('data', result)
        return count

count_issues(self, project_id=None)

Count and return the number of api keys with the given constraints.

Parameters:

Name Type Description Default
project_id Optional[str]

Project ID the issue belongs to.

None

Returns:

Type Description
int

The number of issues with the parameters provided

Source code in kili/queries/issue/__init__.py
@Compatible(['v2'])
@typechecked
def count_issues(self, project_id: Optional[str] = None) -> int:
    """Count and return the number of api keys with the given constraints.

    Args:
        project_id: Project ID the issue belongs to.

    Returns:
        The number of issues with the parameters provided

    """
    variables = {
        'where': {
            'project': {
                'id': project_id,
            },
        },
    }
    result = self.auth.client.execute(GQL_ISSUES_COUNT, variables)
    count = format_result('data', result)
    return count

issues(self, fields=['id', 'createdAt', 'hasBeenSeen', 'issueNumber', 'status', 'type'], first=100, project_id=None, skip=0, disable_tqdm=False, as_generator=False)

Get a generator or a list of issues that match a set of criteria.

Parameters:

Name Type Description Default
fields Optional[List[str]]

All the fields to request among the possible fields for the assets. See the documentation for all possible fields.

['id', 'createdAt', 'hasBeenSeen', 'issueNumber', 'status', 'type']
first Optional[int]

Maximum number of issues to return.

100
project_id Optional[str]

Project ID the issue belongs to.

None
skip Optional[int]

Number of issues to skip (they are ordered by their date of creation, first to last).

0
disable_tqdm bool

If True, the progress bar will be disabled

False
as_generator bool

If True, a generator on the issues is returned.

False

Returns:

Type Description
Union[List[dict], Generator[dict, NoneType]]

A result object which contains the query if it was successful, or an error message.

Examples:

>>> kili.issues(project_id=project_id, fields=['author.email']) # List all issues of a project and their authors
Source code in kili/queries/issue/__init__.py
@Compatible(['v1', 'v2'])
@typechecked
def issues(self,
           fields: Optional[List[str]] = [
               'id',
               'createdAt',
               'hasBeenSeen',
               'issueNumber',
               'status',
               'type'],
           first: Optional[int] = 100,
           project_id: Optional[str] = None,
           skip: Optional[int] = 0,
           disable_tqdm: bool = False,
           as_generator: bool = False) -> Union[List[dict], Generator[dict, None, None]]:
    # pylint: disable=line-too-long
    """Get a generator or a list of issues that match a set of criteria.

    Args:
        fields: All the fields to request among the possible fields for the assets.
            See [the documentation](https://docs.kili-technology.com/reference/graphql-api#issue) for all possible fields.
        first: Maximum number of issues to return.
        project_id: Project ID the issue belongs to.
        skip: Number of issues to skip (they are ordered by their date of creation, first to last).
        disable_tqdm: If `True`, the progress bar will be disabled
        as_generator: If `True`, a generator on the issues is returned.

    Returns:
        A result object which contains the query if it was successful,
            or an error message.

    Examples:
        >>> kili.issues(project_id=project_id, fields=['author.email']) # List all issues of a project and their authors
    """

    count_args = {'project_id': project_id}
    disable_tqdm = disable_tqdm or as_generator
    payload_query = {
        'where': {
            'project': {
                'id': project_id,
            },
        },
    }

    issues_generator = row_generator_from_paginated_calls(
        skip,
        first,
        self.count_issues,
        count_args,
        self._query_issues,
        payload_query,
        fields,
        disable_tqdm
    )

    if as_generator:
        return issues_generator
    return list(issues_generator)