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

Skip child record sync for deleted tickets #149

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
# Changelog

## 2.4.1
* Skip child record sync for deleted tickets [#149](https://github.com/singer-io/tap-zendesk/pull/149)

## 2.4.0
* Upgrades to run on python 3.11.7 [#146](https://github.com/singer-io/tap-zendesk/pull/146)

Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
from setuptools import setup

setup(name='tap-zendesk',
version='2.4.0',
version='2.4.1',
description='Singer.io tap for extracting data from the Zendesk API',
author='Stitch',
url='https://singer.io',
Expand Down
69 changes: 36 additions & 33 deletions tap_zendesk/streams.py
Original file line number Diff line number Diff line change
Expand Up @@ -296,39 +296,42 @@ def emit_sub_stream_metrics(sub_stream):
# yielding stream name with record in a tuple as it is used for obtaining only the parent records while sync
yield (self.stream, ticket)

if audits_stream.is_selected():
try:
for audit in audits_stream.sync(ticket["id"]):
yield audit
except http.ZendeskNotFoundError:
# Skip stream if ticket_audit does not found for particular ticekt_id. Earlier it throwing HTTPError
# but now as error handling updated, it throws ZendeskNotFoundError.
message = "Unable to retrieve audits for ticket (ID: {}), record not found".format(ticket['id'])
LOGGER.warning(message)

if metrics_stream.is_selected():
try:
for metric in metrics_stream.sync(ticket["id"]):
yield metric
except http.ZendeskNotFoundError:
# Skip stream if ticket_metric does not found for particular ticekt_id. Earlier it throwing HTTPError
# but now as error handling updated, it throws ZendeskNotFoundError.
message = "Unable to retrieve metrics for ticket (ID: {}), record not found".format(ticket['id'])
LOGGER.warning(message)

if comments_stream.is_selected():
try:
# add ticket_id to ticket_comment so the comment can
# be linked back to it's corresponding ticket
for comment in comments_stream.sync(ticket["id"]):
yield comment
except http.ZendeskNotFoundError:
# Skip stream if ticket_comment does not found for particular ticekt_id. Earlier it throwing HTTPError
# but now as error handling updated, it throws ZendeskNotFoundError.
message = "Unable to retrieve comments for ticket (ID: {}), record not found".format(ticket['id'])
LOGGER.warning(message)

singer.write_state(state)
# Deleting a ticket will also delete audits, metrics or comments associated with that ticket.
# Therefore skip the child record extraction for deleted tickets
if ticket.get('status', '') != 'deleted':
if audits_stream.is_selected():
try:
for audit in audits_stream.sync(ticket["id"]):
yield audit
except http.ZendeskNotFoundError:
# Skip stream if ticket_audit does not found for particular ticekt_id. Earlier it throwing HTTPError
# but now as error handling updated, it throws ZendeskNotFoundError.
message = "Unable to retrieve audits for ticket (ID: {}), record not found".format(ticket['id'])
LOGGER.warning(message)

if metrics_stream.is_selected():
try:
for metric in metrics_stream.sync(ticket["id"]):
yield metric
except http.ZendeskNotFoundError:
# Skip stream if ticket_metric does not found for particular ticekt_id. Earlier it throwing HTTPError
# but now as error handling updated, it throws ZendeskNotFoundError.
message = "Unable to retrieve metrics for ticket (ID: {}), record not found".format(ticket['id'])
LOGGER.warning(message)

if comments_stream.is_selected():
try:
# add ticket_id to ticket_comment so the comment can
# be linked back to it's corresponding ticket
for comment in comments_stream.sync(ticket["id"]):
yield comment
except http.ZendeskNotFoundError:
# Skip stream if ticket_comment does not found for particular ticekt_id. Earlier it throwing HTTPError
# but now as error handling updated, it throws ZendeskNotFoundError.
message = "Unable to retrieve comments for ticket (ID: {}), record not found".format(ticket['id'])
LOGGER.warning(message)

singer.write_state(state)
emit_sub_stream_metrics(audits_stream)
emit_sub_stream_metrics(metrics_stream)
emit_sub_stream_metrics(comments_stream)
Expand Down