Skip to content

Commit

Permalink
Fix unsync exception condition
Browse files Browse the repository at this point in the history
  • Loading branch information
mawandm committed Apr 22, 2024
1 parent 7bbb4b4 commit 13a31db
Show file tree
Hide file tree
Showing 6 changed files with 76 additions and 160 deletions.
4 changes: 2 additions & 2 deletions nesis/api/core/document_loaders/s3.py
Original file line number Diff line number Diff line change
Expand Up @@ -269,8 +269,8 @@ def _unsync_documents(
try:
client.head_object(Bucket=bucket_name, Key=object_name)
except Exception as ex:
str_ex = str(ex)
if not ("ClientError" in str_ex and "not found" in str_ex.lower()):
str_ex = str(ex).lower()
if not ("object" in str_ex and "not found" in str_ex):
raise
for document_data in rag_metadata.get("data") or []:
try:
Expand Down
11 changes: 10 additions & 1 deletion nesis/api/core/util/dateutil.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,21 @@ def strptime(date_string: str) -> dt.datetime:
"%Y-%m-%d %H:%M:%S",
"%Y%m%d%H%M%S",
"%Y-%m-%d %H:%M:%S.%f",
"%Y-%m-%d %H:%M:%S.%f",
"%Y-%m-%d %H:%M:%S.%f",
"%Y-%m-%d %H:%M:%SZ",
# 2024-04-22 08:30:28+00:00
]
for fmt in formats:
try:
return dt.datetime.strptime(date_string, fmt)
except ValueError:
continue
pass
try:
return dt.datetime.fromisoformat(date_string)
except ValueError:
pass

raise ValueError(
"Date string %s does not match any of the formats %s" % (date_string, formats)
)
Expand Down
2 changes: 1 addition & 1 deletion nesis/api/tests/core/document_loaders/test_s3.py
Original file line number Diff line number Diff line change
Expand Up @@ -257,7 +257,7 @@ def test_unsync_s3_documents(
s3_client = mock.MagicMock()

client.return_value = s3_client
s3_client.head_object.side_effect = Exception("ClientError not found")
s3_client.head_object.side_effect = Exception("HeadObject Not Found")

documents = session.query(Document).all()
assert len(documents) == 1
Expand Down
8 changes: 8 additions & 0 deletions nesis/api/tests/util/test_utils.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
from datetime import datetime

import pytest

from nesis.api.core.util import clean_control
from nesis.api.core.util import dateutil as du


@pytest.mark.parametrize(
Expand All @@ -19,3 +22,8 @@
def test_upload(value, expected) -> None:
result = clean_control(value=value)
assert result == expected


def test_strptime() -> None:
dt = du.strptime("2024-04-22 08:30:28+00:00")
assert isinstance(dt, datetime)
Loading

0 comments on commit 13a31db

Please sign in to comment.