fix(zammad): handle flat list response from search API#470
Open
skjnldsv wants to merge 1 commit into
Open
Conversation
Newer Zammad instances return a flat list of ticket objects from the
search endpoint instead of the `{"assets": {"Ticket": {...}}}` envelope.
Handle both formats: if the response is a list, build the expected
`{id: ticket}` dict directly; otherwise fall through to the existing
assets-unwrap path.
Fixes: TypeError: list indices must be integers or slices, not str
Signed-off-by: John Molakvoæ (skjnldsv) <skjnldsv@protonmail.com>
Author
|
cc @come-nc |
come-nc
reviewed
May 26, 2026
Contributor
There was a problem hiding this comment.
I guess that works.
We actually do not need the keys so it would be cleaner to turn the map into list for older instances instead (and adapt the for to ignore keys in TicketsUpdated::fetch).
The diff I use locally is:
diff --git a/did/plugins/zammad.py b/did/plugins/zammad.py
index 78d331c..15f942e 100644
--- a/did/plugins/zammad.py
+++ b/did/plugins/zammad.py
@@ -59,12 +59,8 @@ class Zammad():
raise ReportError(
f"Zammad search on {self.url} failed.") from error
- def search(self, query: str) -> dict:
- result = self.perform_search(query)["assets"]
- try:
- result = result["Ticket"]
- except KeyError:
- result = {}
+ def search(self, query: str):
+ result = self.perform_search(query)
log.debug("Result: %s fetched", listed(len(result), "item"))
log.data(pretty(result))
return result
@@ -111,7 +107,7 @@ class TicketsUpdated(Stats):
self.stats = []
since = self.options.since.date
until = self.options.until.date
- for _, ticket in self.parent.zammad.search(query).items():
+ for ticket in self.parent.zammad.search(query):
for article in self.parent.zammad.get_articles(ticket["id"]):
updated_at = datetime.fromisoformat(
article["updated_at"].replace('Z', '+00:00')).date()I did not create a PR from it because I did not know how to support both old and new.
4 tasks
DerDreschner
approved these changes
Jun 15, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Newer Zammad instances return a flat list of ticket objects from the
search endpoint instead of the
{"assets": {"Ticket": {...}}}enveloppe.Fix
Detect the response type:
{str(id): ticket}dict directlyassets.Ticketunwrap pathBoth paths produce the same structure consumed by
TicketsUpdated.fetch().Traceback
Tested against a Zammad instance runing the newer API format, confirmed working.