yanyongyu / githubkit

The modern, all-batteries-included GitHub SDK for Python, including rest api, graphql, webhooks, like octokit!
MIT License
158 stars 21 forks source link

Bug: repo activity event issue comment field missing `issue_url` #71

Open IkBenNiet opened 6 months ago

IkBenNiet commented 6 months ago

Kinda strange error occur when I'm trying to get events for repository. It happens in code like:

auth = TokenAuthStrategy(GITHUB_TOKEN)
gh = GitHub(auth=auth)
 async for event in gh.paginate(
        gh.rest.activity.async_list_repo_events,
        owner=owner,
        repo=repository_name,
):
    print(event.repo.name)

Error looks like: unexpected value; permitted: <UNSET> (type=value_error.const; given={'url': 'https://api.github.com/repos/{owner}/{repo}/pulls/comments/{id}', 'pull_request_review_id': {}, 'id': {}, 'node_id': 'PRRC_', 'diff_hunk': "@@ -1154,14 +1162,14 @@ {bunch of code from pr}', 'commit_id': '', 'original_commit_id': '', 'user': {'login': '', 'id': , 'node_id': '', 'avatar_url': 'https://avatars.githubusercontent.com/u/', 'gravatar_id': '', 'url': 'https://api.github.com/users/', 'html_url': 'https://github.com/', 'followers_url': 'https://api.github.com/users/followers', 'following_url': 'https://api.github.com/users/following{/other_user}', 'gists_url': 'https://api.github.com/users/gists{/gist_id}', 'starred_url': 'https://api.github.com/users/starred{/owner}{/repo}', 'subscriptions_url': 'https://api.github.com/users/subscriptions', 'organizations_url': 'https://api.github.com/users/orgs', 'repos_url': 'https://api.github.com/users/repos', 'events_url': 'https://api.github.com/users/events{/privacy}', 'received_events_url': 'https://api.github.com/users/received_events', 'type': 'User', 'site_admin': False}, 'body': "", 'created_at': '2023-12-19T21:52:26Z', 'updated_at': '2023-12-19T21:52:27Z', 'html_url': 'https://github.com/owner/repo/pull/513#discussion_r', 'pull_request_url': 'https://api.github.com/repos/owner/repo/pulls/51', 'author_association': 'CONTRIBUTOR', '_links': {'self': {'href': 'https://api.github.com/repos/owner/repo/pulls/comments/143'}, 'html': {'href': 'https://github.com/owner/repo/pull/512#discussion_r14'}, 'pull_request': {'href': 'https://api.github.com/repos/owner/repo/pulls/53'}}, 'reactions': {'url': 'https://api.github.com/repos/owner/repo/pulls/comments/123/reactions', 'total_count': 0, '+1': 0, '-1': 0, 'laugh': 0, 'hooray': 0, 'confused': 0, 'heart': 0, 'rocket': 0, 'eyes': 0}, 'start_line': None, 'original_start_line': None, 'start_side': None, 'line': 1167, 'original_line': 1167, 'side': 'RIGHT', 'in_reply_to_id': 1431963291, 'original_position': 97, 'position': 97, 'subject_type': 'line'}; permitted=(<UNSET>,)) __root__ -> 98 -> payload -> comment -> issue_url field required (type=value_error.missing)

I have no idea what it means. I've found some issues with similar error. You said it has been fixed in #68 . But as you can see, I still getting it.

Is it any way to fix it?

yanyongyu commented 6 months ago

It seems this is a new schema error. could you please provide the example repo info? As described in the schema provided by github, the issue_url field is required in the payload->comment. You may fire an issue to the https://github.com/github/rest-api-description repo.

Due to the schema issue-comment is used in many fields, the required field issue_url may be hard to change. Currently, you can use the raw json result from response.

IkBenNiet commented 6 months ago

could you please provide the example repo info?

Yes, I tried to get events from some repositories, one of it is node.js repository.

You may fire an issue to the https://github.com/github/rest-api-description repo.

I'll do it. Thanks.

Currently, you can use the raw json result from response.

Sorry, but could you give a details how can I do it in correct way? Is it smth like gh.paginate(gh.request. ...)?

yanyongyu commented 6 months ago

you could provide a custom map_func to the paginator like this:

async for event_dict in gh.paginate(
    gh.rest.activity.async_list_repo_events,
    owner=owner,
    repo=repo,
    map_func=lambda resp: resp.json()
):
    ...

the default map_func is to use the resp.parsed_data to provide data validation and type hints. you can use the response.json() to get the raw json data instead.

IkBenNiet commented 6 months ago

Thanks a lot

IkBenNiet commented 6 months ago
async for event_dict in gh.paginate(
    gh.rest.activity.async_list_repo_events,
    owner=owner,
    repo=repo,
    map_func=lambda resp: resp.json()
):
    .

So, this code raises HTTP exception 422. If I remove map function it return to the beginning. Should I open new issue? Is it error with your lib at all? Full traceback can be found here: https://pasty.lus.pm/ngCEz5

yanyongyu commented 6 months ago

I could not repreduce the error with http 422. but according to the github docs, http 422 indicates "Validation failed, or the endpoint has been spammed."