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,
    ) -> Iterable[dict]:
        # 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
        """
        where = IssueWhere(project_id=project_id)
        options = QueryOptions(disable_tqdm, first, skip, as_generator)
        return IssueQuery(self.auth.client)(where, fields, options)

    @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

        """
        if not project_id:
            warnings.warn(
                "It is now required to provide a project_id when calling count_issues. This change"
                " will be enforced from 01/02/2023",
                DeprecationWarning,
            )
        where = IssueWhere(project_id=project_id)
        return IssueQuery(self.auth.client).count(where)

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

    """
    if not project_id:
        warnings.warn(
            "It is now required to provide a project_id when calling count_issues. This change"
            " will be enforced from 01/02/2023",
            DeprecationWarning,
        )
    where = IssueWhere(project_id=project_id)
    return IssueQuery(self.auth.client).count(where)

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
Iterable[dict]

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,
) -> Iterable[dict]:
    # 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
    """
    where = IssueWhere(project_id=project_id)
    options = QueryOptions(disable_tqdm, first, skip, as_generator)
    return IssueQuery(self.auth.client)(where, fields, options)

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:
            options = QueryOptions(disable_tqdm=True)
            where = LabelWhere(
                project_id=project_id,
                label_id=label_id,
            )
            asset_id = cast(
                List[Dict],
                list(
                    LabelQuery(self.auth.client)(
                        where=where, fields=["labelOf.id"], options=options
                    )
                )[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:
        options = QueryOptions(disable_tqdm=True)
        where = LabelWhere(
            project_id=project_id,
            label_id=label_id,
        )
        asset_id = cast(
            List[Dict],
            list(
                LabelQuery(self.auth.client)(
                    where=where, fields=["labelOf.id"], options=options
                )
            )[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)