fix gitlab-connector - wrong datetime format (#1559)

This commit is contained in:
NP
2024-06-04 19:41:19 +02:00
committed by GitHub
parent b6d0ecec4f
commit 4d5a39628f

View File

@@ -6,6 +6,7 @@ from datetime import timezone
from typing import Any from typing import Any
import gitlab import gitlab
import pytz
from danswer.configs.app_configs import INDEX_BATCH_SIZE from danswer.configs.app_configs import INDEX_BATCH_SIZE
from danswer.configs.constants import DocumentSource from danswer.configs.constants import DocumentSource
@@ -114,12 +115,14 @@ class GitlabConnector(LoadConnector, PollConnector):
doc_batch: list[Document] = [] doc_batch: list[Document] = []
for mr in mr_batch: for mr in mr_batch:
mr.updated_at = datetime.strptime( mr.updated_at = datetime.strptime(
mr.updated_at, "%Y-%m-%dT%H:%M:%S.%fZ" mr.updated_at, "%Y-%m-%dT%H:%M:%S.%f%z"
) )
if start is not None and mr.updated_at < start: if start is not None and mr.updated_at < start.replace(
tzinfo=pytz.UTC
):
yield doc_batch yield doc_batch
return return
if end is not None and mr.updated_at > end: if end is not None and mr.updated_at > end.replace(tzinfo=pytz.UTC):
continue continue
doc_batch.append(_convert_merge_request_to_document(mr)) doc_batch.append(_convert_merge_request_to_document(mr))
yield doc_batch yield doc_batch
@@ -131,13 +134,17 @@ class GitlabConnector(LoadConnector, PollConnector):
doc_batch = [] doc_batch = []
for issue in issue_batch: for issue in issue_batch:
issue.updated_at = datetime.strptime( issue.updated_at = datetime.strptime(
issue.updated_at, "%Y-%m-%dT%H:%M:%S.%fZ" issue.updated_at, "%Y-%m-%dT%H:%M:%S.%f%z"
) )
if start is not None and issue.updated_at < start: if start is not None:
yield doc_batch start = start.replace(tzinfo=pytz.UTC)
return if issue.updated_at < start:
if end is not None and issue.updated_at > end: yield doc_batch
continue return
if end is not None:
end = end.replace(tzinfo=pytz.UTC)
if issue.updated_at > end:
continue
doc_batch.append(_convert_issue_to_document(issue)) doc_batch.append(_convert_issue_to_document(issue))
yield doc_batch yield doc_batch