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

Work around paginator flaw by querying issues in descending order #110

Open
wants to merge 1 commit 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
Work around paginator flaw by querying issues in descending order
  • Loading branch information
gnilrets committed Jun 28, 2023
commit d168ffe1aa33ce0252fa2cb77a30e6ff007a1138
1 change: 1 addition & 0 deletions tap_jira/http.py
Original file line number Diff line number Diff line change
Expand Up @@ -230,6 +230,7 @@ def send(self, method, path, headers={}, **kwargs):
auth=self.auth,
headers=self._headers(headers),
**kwargs)
LOGGER.info("Sending API request to %s with params %s", request.url, kwargs)
return self.session.send(request.prepare(), timeout=self.timeout)

@backoff.on_exception(backoff.constant,
Expand Down
14 changes: 12 additions & 2 deletions tap_jira/streams.py
Original file line number Diff line number Diff line change
Expand Up @@ -304,7 +304,14 @@ def sync(self):
timezone = Context.retrieve_timezone()
start_date = last_updated.astimezone(pytz.timezone(timezone)).strftime("%Y-%m-%d %H:%M")

jql = "updated >= '{}' order by updated asc".format(start_date)
# Results cannot be ordered in ascending order because the Jira API reruns the query
# as we page through the results. This means that if a record is
# updated after we've seen it on a page, it will jump to a later page, but a record
# we haven't seen yet can slip to a page we've already queried (https://github.com/singer-io/tap-jira/issues/109#issuecomment-1610335683).
# Querying the data in descending order works around this problem. It's possible to get
# duplicates if a record is updated after it's been seen on a page, but those dupes can be
# removed later.
jql = "updated >= '{}' order by updated desc".format(start_date)
params = {"fields": "*all",
"expand": "changelog,transitions",
"validateQuery": "strict",
Expand All @@ -329,7 +336,10 @@ def sync(self):
issue['fields'].pop('operations', None)

# Grab last_updated before transform in write_page
last_updated = utils.strptime_to_utc(page[-1]["fields"]["updated"])
last_updated = max(
utils.strptime_to_utc(page[0]["fields"]["updated"]),
last_updated
)

self.write_page(page)

Expand Down