Skip to content

Commit 7cba8f1

Browse files
authored
fix(timezone): ensured consistent timezone conversion in PR processing (#638)
* fix(timezone): ensured consistent timezone conversion in PR processing * fix(timestamp): code formatted with black integration
1 parent c0eaf63 commit 7cba8f1

File tree

1 file changed

+10
-8
lines changed

1 file changed

+10
-8
lines changed

backend/analytics_server/mhq/service/code/sync/etl_github_handler.py

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -112,9 +112,11 @@ def get_repo_pull_requests_data(
112112
if not prs:
113113
break
114114

115-
if prs[-1].updated_at.astimezone(tz=pytz.UTC) <= bookmark:
115+
if prs[-1].updated_at.replace(tzinfo=pytz.UTC) <= bookmark:
116116
prs_to_process += [
117-
pr for pr in prs if pr.updated_at.astimezone(tz=pytz.UTC) > bookmark
117+
pr
118+
for pr in prs
119+
if pr.updated_at.replace(tzinfo=pytz.UTC) > bookmark
118120
]
119121
break
120122

@@ -125,7 +127,7 @@ def get_repo_pull_requests_data(
125127
state_changed_at = pr.merged_at if pr.merged_at else pr.closed_at
126128
if (
127129
pr.state.upper() != PullRequestState.OPEN.value
128-
and state_changed_at.astimezone(tz=pytz.UTC) < bookmark
130+
and state_changed_at.replace(tzinfo=pytz.UTC) < bookmark
129131
):
130132
continue
131133
if pr not in filtered_prs:
@@ -224,9 +226,9 @@ def _to_pr_model(
224226
state_changed_at = None
225227
if state != PullRequestState.OPEN:
226228
state_changed_at = (
227-
pr.merged_at.astimezone(pytz.UTC)
229+
pr.merged_at.replace(tzinfo=pytz.UTC)
228230
if pr.merged_at
229-
else pr.closed_at.astimezone(pytz.UTC)
231+
else pr.closed_at.replace(tzinfo=pytz.UTC)
230232
)
231233

232234
merge_commit_sha: Optional[str] = self._get_merge_commit_sha(pr.raw_data, state)
@@ -236,8 +238,8 @@ def _to_pr_model(
236238
number=str(pr.number),
237239
title=pr.title,
238240
url=pr.html_url,
239-
created_at=pr.created_at.astimezone(pytz.UTC),
240-
updated_at=pr.updated_at.astimezone(pytz.UTC),
241+
created_at=pr.created_at.replace(tzinfo=pytz.UTC),
242+
updated_at=pr.updated_at.replace(tzinfo=pytz.UTC),
241243
state_changed_at=state_changed_at,
242244
state=state,
243245
base_branch=pr.base.ref,
@@ -300,7 +302,7 @@ def _to_pr_events(
300302
pull_request_id=str(pr_model.id),
301303
type=PullRequestEventType.REVIEW.value,
302304
data=review.raw_data,
303-
created_at=review.submitted_at.astimezone(pytz.UTC),
305+
created_at=review.submitted_at.replace(tzinfo=pytz.UTC),
304306
idempotency_key=str(review.id),
305307
org_repo_id=pr_model.repo_id,
306308
actor_username=username,

0 commit comments

Comments
 (0)