zenpy
zenpy copied to clipboard
Update Ticket - Changing Requester
If you update a ticket and added a different requester, the update payload for the user only contains id and name. If we add "email" to the User._always_dirty set, it correctly sends Zendesk the user dictionary with id, name, email and Zendesk now sets the requester to the existing user instead of creating a new user every time it puts the ticket data.
Sounds like a bug. If you have a small snippet that reproduces this issue it would help greatly.
Fetch a ticket. Search for an end-user (I was using custom field). Make sure the user has an email address assigned. Set the ticket requester to the user Call update(ticket). When the request is submitted the ticket requester data for the request becomes {id: user.id, name: user.name} Zendesk creates a new user without an email and sets the new user as the requested. I read Zendesks docs and unless an email is provided, a new user is created. So by flagging email as dirty. The request data then includes email, and Zendesk correctly updates the requester without creating a new user I can make an actual snippet if you still want.
I don't have much time to work on Zenpy so if you can create a snippet that easily reproduces this issue I'll be more likely to find the time to fix it.
As I'm facing this issue now aswell when creating tickets, here is a minimal snippet:
zen = Zenpy(**creds)
user = User(name="Jon Doe", email="[email protected]", verified=True)
user = zen.users.create(user) # User is created just fine
# create a ticket
ticket = Ticket(subject="Subject", description="Text", submitter=user, requester=user)
audit = zen.tickets.create(ticket)
created_ticket = audit.ticket
print(created_ticket.submitter) # The freshly created user
print(created_ticket.requester) # This is a completely new user
print( created_ticket.requester.email is None ) # Prints True
Basically, when assigning a requester, the created tickets requester is a completely different newly created user. I haven't found a workaround yet to make this work. @csheldrick did you ever get this working?
Hello! @Orangensaft I faced similar issue to yours in our production code. For me, the solution was using only requester_id instead of passing the requester object to the Ticket constructor.
ticket = Ticket(subject="Subject", description="Text", submitter=user, requester_id=user.id)
The requester setter seems to set both _requester
and requester_id
fields in the code. I had no time to investigate it further but my assumption is that the code does not fetch the user if the _requestor is not None
but the _requestor
also has everything inside while being copied to the Ticket object.
But the POST body does not contain much information.
I don't have enough Python skills to dig deeper in the code either :D
The fix I used would be implemented like this:
zen = Zenpy(**creds)
user = User(name="Jon Doe", email="[email protected]", verified=True)
user = zen.users.create(user) # User is created just fine
user._always_dirty.add("email") # NOTE: This will fix your issue.
# create a ticket
ticket = Ticket(subject="Subject", description="Text", submitter=user, requester=user)
audit = zen.tickets.create(ticket)
created_ticket = audit.ticket
print(created_ticket.submitter) # The freshly created user
print(created_ticket.requester) # This is a completely new user
print( created_ticket.requester.email is None ) # Prints False now.