fastai / ghapi

A delightful and complete interface to GitHub's amazing API
https://ghapi.fast.ai/
Apache License 2.0
527 stars 57 forks source link

Recommended way of sending null as a parameter #81

Closed SirRender00 closed 3 months ago

SirRender00 commented 3 years ago

Hey, I've run into an issue where I can't figure out how to send null as required by some endpoints by the Github API, (specifically updating branch protection). This endpoint requires parameters of type object or nullable. I've tried var=None, var='null', var='', var={}. All are met with a HTTP422 Error: Unprocessable Entity (as opposed to specifying the values which work fine). Any help would be appreciated.

salgo commented 2 years ago

I would also like to ask this one. I am also trying to update branch protection and cannot send Null. Can anyone help?

chebee7i commented 2 years ago

Hey any update on this? There are API endpoints that are broken presently. For required arguments, values of None must be converted to null and explicitly sent.

tide-jamiegwatkin commented 2 years ago

I'm also seeing this issue, we've had to drop down to using the requests library where API calls via ghapi error out.

drahamim commented 1 year ago

I'm seeing this issue too. Running v1.0.3. python 3.10

chebee7i commented 1 year ago

Any updates?

raeganbarker commented 1 year ago

I'm seeing this issue as well when using repos.update_branch_protection, since null is valid input for some of that endpoint's parameters.

It looks like the issue stems from this statement, which drops any key-value pairs where the value is None. https://github.com/fastai/ghapi/blob/b77bfaebd937a3b7527b117a5e43d99bcb98b39d/ghapi/core.py#L59

I tried removing that if condition like so:

kwargs = {k: v for k, v in kwargs.items()}

And I'm now able to use the endpoint I previously mentioned without any issues.

Your mileage may vary.

EDIT: Or, if you actually want to do this the right way, you can just remove that line entirely, since it doesn't do anything of consequence once that if is removed. 😉

DavidSolWizeline commented 11 months ago

It worked for me

shreve commented 6 months ago

Chiming in to say this is still an issue, particularly for update_branch_protection.

All of these fields accept null on the GitHub API side, but cannot be set as such using ghapi.

gh.repos.update_branch_protection(
    ...,
    required_status_checks=None,
    enforce_admins=None,
    required_pull_request_reviews=None,
    restrictions=None,
    allow_force_pushes=None,
)

It appears that this method is currently unusable to unset these fields because null is the only way to do so. In order to do so, you can use GhApi.__call__ even though it's not very nice.

gh(f"/repos/{owner}/{repo}/branches/{branch}/protection", "PUT", data=b"""
    {
        ...
        "required_status_checks": null,
        "enforce_admins": null,
        "required_pull_request_reviews": null,
        "restrictions": null,
        "allow_force_pushes": null
    }
""")

This is tested working with v1.0.4

chebee7i commented 4 months ago

Seems like this project might be abandoned.

SirRender00 commented 4 months ago

Personally, I've given up on this library and just wrap around the API natively with requests or gql. With Github API supporting versioning as a header, this library is not worth the hassle in my opinion.

jph00 commented 3 months ago

Seems like this project might be abandoned.

It's definitely not abandoned. No one at-mentioned me so I didn't get notified however.

Has anyone tried the suggested approach by @raeganbarker of removing that line to check whether all tests are still passed? If so, I'm happy to make that update (or someone could do a PR).

shreve commented 3 months ago

@jph00 I made a PR. One test is failing, but it appears to require write access to the fastai/ghapi-test repo, so I think we're good. I can confirm my use case from above now works. https://github.com/fastai/ghapi/issues/81#issuecomment-1892671885

jph00 commented 3 months ago

Super -- really great to have this resolved. :D

chebee7i commented 3 months ago

It's definitely not abandoned. No one at-mentioned me so I didn't get notified however.

What does this mean, precisely? The issue is years old, and there are only 43 issues in the entire repository. So I'd think maintainers would be looking actively at open tickets.

jph00 commented 3 months ago

What does this mean, precisely?

It means a single volunteer, me, is looking after dozens of projects largely on my own, so I'd like some basic level of help from the community of people who use my work for free. Is at-mentioning me really too much to ask?

feanil commented 3 months ago

@shreve thanks for making the PR and @jph00 thanks for reviewing and landing!