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

HTTP Error 422: Unprocessable Entity returned for issues.add_labels in version 0.1.17 #69

Closed
jhlegarreta opened this issue Jun 4, 2021 · 11 comments
Labels
bug Something isn't working

Comments

@jhlegarreta
Copy link

I'm having issues with the ghapi 0.1.17 version released on May, 24th.

I have a private project where I use ghapi to automatically label PRs and issues based on the path of the files mentioned or modified, and the title of the PR/issue. I am using the following public project to test the workflows and scripts:
https://github.com/jhlegarreta/labelertest

The labeler on the PR/issue title was working fine with ghapi 0.1.16, but it is systematically returning an HTTP Error 422: Unprocessable Entity error for the following call:

api.issues.add_labels(
            accept="application/vnd.github.v3+json",
            issue_number=pull_request.number, labels=title_labels_to_add)

where the issue_number and labels have the appropriate values.

Here is an example of a successful call using 0.1.16:
https://github.com/jhlegarreta/labelertest/runs/2750092407?check_suite_focus=true#step:5:495

And here is an example of a successful call using 0.1.17:
https://github.com/jhlegarreta/labelertest/runs/2750038846?check_suite_focus=true#step:5:505

for the same contents from the viewpoint of the files added in the PRs and their titles.

I have not found any release notes notifying about changes, or an older version of the documentation. According to the latest documentation:
https://docs.github.com/en/rest/reference/issues#add-labels-to-an-issue

I would be providing the expected parameters to the call.

For what is worth, the 0.1.16 was also working when I only had:

api.issues.add_labels(pull_request.number, title_labels_to_add)

but 0.1.17 failed as described, so the parameters seem not to be the problem.

The relevant GitHub workflow file is https://github.com/jhlegarreta/labelertest/blob/main/.github/workflows/pr_title_labeler.yml, and the Python script containing the calls to the ghapi is https://github.com/jhlegarreta/labelertest/blob/main/.github/scripts/pr_title_regex_labeler.py

Would you please be able to tell what I am doing wrong.

Thanks for providing us with this valuable tool and thanks for the support.

@roy-ht
Copy link

roy-ht commented Jun 24, 2021

@lemonshir
Copy link

Hi team, we met the same problem when using the API repos.create_or_update_file_contents. The version we are using is ghapi==0.1.17. Could you help take a look? Thanks!

@lemonshir
Copy link

Hi team, we met the same issue when calling another API. Could you help take a look? Thanks!

api.orgs.create_invitation('gm-test-org', '14024832')
---------------------------------------------------------------------------
HTTP422UnprocessableEntityError           Traceback (most recent call last)
<ipython-input-3-c1bd346371d5> in <module>
----> 1 api.orgs.create_invitation('gm-test-org', '14024832')

~/pyvenvs/osm/lib/python3.6/site-packages/ghapi/core.py in __call__(self, headers, *args, **kwargs)
     60         route_p,query_p,data_p = [{p:kwargs[p] for p in o if p in kwargs}
     61                                  for o in (self.route_ps,self.params,d)]
---> 62         return self.client(self.path, self.verb, headers=headers, route=route_p, query=query_p, data=data_p)
     63 
     64     def __str__(self): return f'{self.tag}.{self.name}{signature(self)}\n{self.doc_url}'

~/pyvenvs/osm/lib/python3.6/site-packages/ghapi/core.py in __call__(self, path, verb, headers, route, query, data)
    104         if path[:7] not in ('http://','https:/'): path = GH_HOST+path
    105         res,self.recv_hdrs = urlsend(path, verb, headers=headers or None, debug=self.debug, return_headers=True,
--> 106                                      route=route or None, query=query or None, data=data or None)
    107         if 'X-RateLimit-Remaining' in self.recv_hdrs:
    108             newlim = self.recv_hdrs['X-RateLimit-Remaining']

~/pyvenvs/osm/lib/python3.6/site-packages/fastcore/net.py in urlsend(url, verb, headers, route, query, data, json_data, return_json, return_headers, debug)
    177         return urlread(req, decode=False, return_json=False, return_headers=return_headers)
    178 
--> 179     return urlread(req, return_json=return_json, return_headers=return_headers)
    180 
    181 # Cell

~/pyvenvs/osm/lib/python3.6/site-packages/fastcore/net.py in urlread(url, data, headers, decode, return_json, return_headers, **kwargs)
    110         with urlopen(url, data=data, headers=headers, **kwargs) as u: res,hdrs = u.read(),u.headers
    111     except HTTPError as e:
--> 112         if 400 <= e.code < 500: raise ExceptionsHTTP[e.code](e.url, e.hdrs, e.fp) from None
    113         else: raise
    114 

HTTP422UnprocessableEntityError: HTTP Error 422: Unprocessable Entity

@lemonshir
Copy link

@jph00 @hamelsmu could you help take a look when you get a chance? Thanks!

@hamelsmu
Copy link
Contributor

I'll take a look within next week or so

@hamelsmu
Copy link
Contributor

hamelsmu commented Jul 2, 2021

This is something I tried to debug, but it isn't a quick fix (or at least something I wasn't able to fix). I shared everything I could with @jph00, perhaps he might be able to help with this one. I suspect many of the open issues in this repo could be correlated.

@lemonshir
Copy link

Thanks for your investigation, Hamel! I hope @jph00 could help on this issue.

@jph00
Copy link
Contributor

jph00 commented Jul 9, 2021

Hi team, we met the same problem when using the API repos.create_or_update_file_contents. The version we are using is ghapi==0.1.17. Could you help take a look? Thanks!

I've looked at this one and it's working fine in our tests. You can see a working example in the definition in the lib of update_contents(). Please take a look at this example and see if you can use it to help you get your working. If you can't, please create a new issue for this including your code and stack trace.

@jph00
Copy link
Contributor

jph00 commented Jul 9, 2021

Hi team, we met the same issue when calling another API. Could you help take a look?

I just tried calling that endpoint and it worked for me. Maybe you're using the wrong id? Note that you can use an email address instead, if you use the 'email' param.

@jph00 jph00 added the bug Something isn't working label Jul 9, 2021
@jph00 jph00 closed this as completed in d8e558c Jul 9, 2021
@jph00
Copy link
Contributor

jph00 commented Jul 9, 2021

@jhlegarreta @roy-ht I've just cut a release which resolves the add_labels problem in my testing. Please reopen if you still have the same issue with the latest version.

(The issue was due to a change in the OpenAPI spec to use OpenAPI functionality that previously wasn't used, so wasn't handled by ghapi.)

@jhlegarreta
Copy link
Author

jhlegarreta commented Jul 27, 2021

@jph00 thanks for the effort and sorry for the delay in updating.

I've tested the 0.1.18 release as the minimum version fixing the issue and it did work successfully, and hence the patch set fixed the issue:
https://github.com/jhlegarreta/labelertest/pull/22/checks?check_run_id=3166906022#step:5:495

Thanks 💯 !!

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

No branches or pull requests

5 participants