Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Type checking error when using created filter in list_workflow_runs function #137

Closed
oscarsj opened this issue Sep 24, 2024 · 3 comments · Fixed by #139
Closed

Type checking error when using created filter in list_workflow_runs function #137

oscarsj opened this issue Sep 24, 2024 · 3 comments · Fixed by #139
Labels
bug Something isn't working Rest API schema schema related

Comments

@oscarsj
Copy link

oscarsj commented Sep 24, 2024

When I use list_workflow_run functions I'm using created parameter to filter out workflow runs. The way of using this parameter is by providing a string with an arithmetic comparison and a stringified datetime, something like:

wfs = github.rest.actions.list_workflow_runs(
    owner=owner,
    repo=repo_name,
    workflow_id=workflow_id,
    branch=branch_name,
    event="workflow_dispatch",
    created=f">={dispatch_time.strftime('%Y-%m-%dT%H:%M:%SZ')}",
).parsed_data

as you can see, the type of the created parameter is a str.

But when I run mypy type checking over this piece of code, I get:

pip freeze | grep -i githubkit
GitHubKit==0.11.8

mypy scripts/test.py
scripts/test.py:25: error: Argument "created" to "list_workflow_runs" of "ActionsClient" has incompatible type "str"; expected "Literal[Unset._UNSET] | datetime | None"  [arg-type]
Found 1 error in 1 file (checked 1 source file)

This type checking result is misleading and breaks our automated type-safety checks.

This started happening in version 0.11.8. I think this behaviour can be traced to this line changed:

Missing: TypeAlias = Union[UnsetType, T, None]

on PR https://github.com/yanyongyu/githubkit/pull/117/files#diff-70cf106ab334e2539867d80d8c49a85c44184d1d8c319b3a95c1484a0e5cafbdR83

If I downgrade to 0.11.7 and run mypy, I get no errors:

pip freeze | grep -i githubkit
GitHubKit==0.11.7

mypy scripts/test.py
Success: no issues found in 1 source file

The script I used to test that the created filter indeed was working and expecting a string is:
https://gist.github.com/oscarsj/600804cb56752ea0047c82220173162b

The expected behaviour is that created parameter (and possibly other datetime-like params used for filtering) has a type compatible with str.

@yanyongyu yanyongyu added bug Something isn't working schema schema related Rest API labels Sep 25, 2024
@yanyongyu
Copy link
Owner

This is due to the github openapi schema change. In the latest schema, the created query is described as:

created:
  name: created
  description: Returns workflow runs created within the given date-time range.
    For more information on the syntax, see "[Understanding the search syntax](https://docs.github.com/search-github/getting-started-with-searching-on-github/understanding-the-search-syntax#query-for-dates)."
  in: query
  required: false
  schema:
    type: string
    format: date-time

The format of the field is set to date-time. We need to make a patch to override this.

@oscarsj
Copy link
Author

oscarsj commented Sep 27, 2024

Thanks for the swift reaction! ❤

@yanyongyu
Copy link
Owner

This will be addressed in the next release 😄

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working Rest API schema schema related
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants