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

Unexpected KeyError when creating new JIRA link. #662

Closed
alsmith opened this issue Nov 1, 2024 · 7 comments
Closed

Unexpected KeyError when creating new JIRA link. #662

alsmith opened this issue Nov 1, 2024 · 7 comments

Comments

@alsmith
Copy link

alsmith commented Nov 1, 2024

I'm trying to add a new link from a Zendesk ticket to a JIRA issue.

link = zenpy.lib.api_objects.Link(ticket_id=ticket.id, issue_id=issue.id, issue_key=issue.key)
result = zendeskClient.jira_links.create(link)

This does actually create a new link in the ticket, unfortunately the python code returns the following error. Using zenpy 2.0.54.

Traceback (most recent call last):
  File "link.py", line 51, in <module>
    sys.exit(main())
  File "link.py", line 46, in main
    result = zendeskClient.jira_links.create(link)
  File ".env/lib/python3.7/site-packages/zenpy/lib/api.py", line 614, in create
    return CRUDRequest(self).post(api_objects, **kwargs)
  File ".env/lib/python3.7/site-packages/zenpy/lib/request.py", line 82, in post
    return self.api._post(url, payload)
  File ".env/lib/python3.7/site-packages/zenpy/lib/api.py", line 157, in _post
    return self._process_response(response)
  File ".env/lib/python3.7/site-packages/zenpy/lib/api.py", line 293, in _process_response
    r = handler(self, object_mapping).build(response)
  File ".env/lib/python3.7/site-packages/zenpy/lib/response.py", line 140, in build
    return JiraLinkGenerator(self, response_json, response)
  File ".env/lib/python3.7/site-packages/zenpy/lib/generator.py", line 362, in __init__
    object_type='links')
  File ".env/lib/python3.7/site-packages/zenpy/lib/generator.py", line 186, in __init__
    self.values = response_objects or self.process_page() or None
  File ".env/lib/python3.7/site-packages/zenpy/lib/generator.py", line 191, in process_page
    return response_objects[as_plural(self.object_type)]
KeyError: 'links'
@cryptomail
Copy link
Collaborator

Welp looks like I'll have to analyze this :) Thanks for your report. I don't like crashbugs...I'll try to dip it in sugar and eat it :) Give me a few days.

@alsmith
Copy link
Author

alsmith commented Nov 3, 2024

Let me know if I can help in any way.

@cryptomail
Copy link
Collaborator

Let me know if I can help in any way.

All good, I'll likely reproduce it locally and trace it back to the call and the missing/incorrect nodes in the response JSON. Bummer it wasn't tested. I've been on a campaign of adding tests (real integration tests) for all endpoints. If and when I find the root cause of this, likely I'll ensure it's codified in a test.

@cryptomail
Copy link
Collaborator

Formally starting investigation:
From API specification perspective, let's look at https://developer.zendesk.com/api-reference/ticketing/jira/links/#create-link
The purported response has the following (gif) structure:
Screenshot 2024-11-06 at 9 35 22 AM
It does appear that a pluralization error is the root cause, at surface value.
That's where I'll start my trace, as the code is complaining about missing PLURAL links when link is the purported result set.

@cryptomail
Copy link
Collaborator

cryptomail commented Nov 7, 2024

Here's what came back:

{"link":{"id":60464179,"ticket_id":"20854","issue_id":"5461","issue_key":"153425890A","url":"https://myinstance.zendesk.com/api/services/jira/links/60464179","created_at":"2024-11-07T17:56:27.000Z","updated_at":"2024-11-07T17:56:27.000Z"}}

I'll try to see why this was not processed correctly.

@cryptomail
Copy link
Collaborator

@alsmith Do you want to try #664 and see if it works....it does seem to work for me :)

@cryptomail
Copy link
Collaborator

Sorry just pushed latest changes to branch. AND ADDED TEST!!!

cryptomail added a commit that referenced this issue Nov 8, 2024
…f_necessary

Fix: Issue #662 add more flexibility in base class for object type
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants