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
    @typechecked
    def issues(
        self,
        project_id: str,
        fields: List[str] = [
            "id",
            "createdAt",
            "hasBeenSeen",
            "issueNumber",
            "status",
            "type",
        ],
        first: Optional[int] = None,
        skip: 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:
            project_id: Project ID the issue belongs to.
            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.
            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)

    @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 int(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
@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 int(count)

issues(self, project_id, fields=['id', 'createdAt', 'hasBeenSeen', 'issueNumber', 'status', 'type'], first=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
project_id str

Project ID the issue belongs to.

required
fields 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.

None
skip 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
@typechecked
def issues(
    self,
    project_id: str,
    fields: List[str] = [
        "id",
        "createdAt",
        "hasBeenSeen",
        "issueNumber",
        "status",
        "type",
    ],
    first: Optional[int] = None,
    skip: 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:
        project_id: Project ID the issue belongs to.
        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.
        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)

Mutations

Set of Issue mutations.

Source code in kili/mutations/issue/__init__.py
class MutationsIssue:
    """Set of Issue mutations."""

    # pylint: disable=too-few-public-methods,too-many-arguments,too-many-locals

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

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

    @typechecked
    def append_to_issues(
        self,
        label_id: str,
        project_id: str,
        object_mid: Optional[str] = None,
        text: Optional[str] = None,
        type_: Literal["ISSUE", "QUESTION"] = "ISSUE",
    ) -> Dict:
        """Create an issue.

        Args:
            label_id: Id of the label to add an issue to
            object_mid: Mid of the object in the label to associate the issue to
            type_: type of the issue to add. Can be either "ISSUE" or "QUESTION"
            text: If given, write a comment related to the issue
            project_id: Id of the project

        Returns:
            A result object which indicates if the mutation was successful,
                or an error message.
        """
        issue_number = get_issue_number(self.auth, project_id, type_)
        try:
            asset_id = cast(
                List[Dict],
                list(
                    QueriesLabel(self.auth).labels(
                        project_id=project_id,
                        label_id=label_id,
                        fields=["labelOf.id"],
                        disable_tqdm=True,
                    )
                )[0]["labelOf"]["id"],
            )
        except:
            # pylint: disable=raise-missing-from
            raise ValueError(
                f"Label ID {label_id} does not exist in the project of ID {project_id}"
            )
        variables = {
            "data": {
                "issueNumber": issue_number,
                "labelID": label_id,
                "objectMid": object_mid,
                "type": type_,
            },
            "where": {"id": asset_id},
        }
        if text:
            variables["data"]["text"] = text

        result = self.auth.client.execute(GQL_APPEND_TO_ISSUES, variables)
        return format_result("data", result)

append_to_issues(self, label_id, project_id, object_mid=None, text=None, type_='ISSUE')

Create an issue.

Parameters:

Name Type Description Default
label_id str

Id of the label to add an issue to

required
object_mid Optional[str]

Mid of the object in the label to associate the issue to

None
type_ typing_extensions.Literal['ISSUE', 'QUESTION']

type of the issue to add. Can be either "ISSUE" or "QUESTION"

'ISSUE'
text Optional[str]

If given, write a comment related to the issue

None
project_id str

Id of the project

required

Returns:

Type Description
Dict

A result object which indicates if the mutation was successful, or an error message.

Source code in kili/mutations/issue/__init__.py
@typechecked
def append_to_issues(
    self,
    label_id: str,
    project_id: str,
    object_mid: Optional[str] = None,
    text: Optional[str] = None,
    type_: Literal["ISSUE", "QUESTION"] = "ISSUE",
) -> Dict:
    """Create an issue.

    Args:
        label_id: Id of the label to add an issue to
        object_mid: Mid of the object in the label to associate the issue to
        type_: type of the issue to add. Can be either "ISSUE" or "QUESTION"
        text: If given, write a comment related to the issue
        project_id: Id of the project

    Returns:
        A result object which indicates if the mutation was successful,
            or an error message.
    """
    issue_number = get_issue_number(self.auth, project_id, type_)
    try:
        asset_id = cast(
            List[Dict],
            list(
                QueriesLabel(self.auth).labels(
                    project_id=project_id,
                    label_id=label_id,
                    fields=["labelOf.id"],
                    disable_tqdm=True,
                )
            )[0]["labelOf"]["id"],
        )
    except:
        # pylint: disable=raise-missing-from
        raise ValueError(
            f"Label ID {label_id} does not exist in the project of ID {project_id}"
        )
    variables = {
        "data": {
            "issueNumber": issue_number,
            "labelID": label_id,
            "objectMid": object_mid,
            "type": type_,
        },
        "where": {"id": asset_id},
    }
    if text:
        variables["data"]["text"] = text

    result = self.auth.client.execute(GQL_APPEND_TO_ISSUES, variables)
    return format_result("data", result)