Skip to content

Commit 2a6f2dd

Browse files
authored
Merge pull request #308 from superannotateai/friday
Friday
2 parents 8cc5a68 + 9ce3e73 commit 2a6f2dd

File tree

2 files changed

+48
-10
lines changed

2 files changed

+48
-10
lines changed

src/superannotate/lib/core/entities/utils.py

Lines changed: 3 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -110,18 +110,11 @@ class TimedBaseModel(BaseModel):
110110
created_at: constr(regex=DATE_REGEX) = Field(None, alias="createdAt")
111111
updated_at: constr(regex=DATE_REGEX) = Field(None, alias="updatedAt")
112112

113-
@validator("created_at", pre=True)
113+
@validator("created_at", "updated_at" , pre=True)
114114
def validate_created_at(cls, value):
115115
try:
116-
constr(regex=DATE_REGEX).validate(value)
117-
except (TypeError, StrRegexError):
118-
raise TypeError(DATE_TIME_FORMAT_ERROR_MESSAGE)
119-
return value
120-
121-
@validator("updated_at", pre=True)
122-
def validate_updated_at(cls, value):
123-
try:
124-
constr(regex=DATE_REGEX).validate(value)
116+
if value is not None:
117+
constr(regex=DATE_REGEX).validate(value)
125118
except (TypeError, StrRegexError):
126119
raise TypeError(DATE_TIME_FORMAT_ERROR_MESSAGE)
127120
return value

tests/unit/test_validators.py

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -352,3 +352,48 @@ def test_validate_document_annotation_wrong_class_id(self):
352352
sa.validate_annotations("Document", os.path.join(self.vector_folder_path, f"{tmpdir_name}/test_validate_document_annotation_wrong_class_id.json"))
353353
self.assertIn("instances[0].classIdintegertypeexpected", out.getvalue().strip().replace(" ", ""))
354354

355+
356+
def test_validate_document_annotation_with_null_created_at(self):
357+
with tempfile.TemporaryDirectory() as tmpdir_name:
358+
with open(f"{tmpdir_name}/test_validate_document_annotation_with_null_created_at.json", "w") as test_validate_document_annotation_with_null_created_at:
359+
test_validate_document_annotation_with_null_created_at.write(
360+
'''
361+
{
362+
"metadata": {
363+
"name": "text_file_example_1",
364+
"status": "NotStarted",
365+
"url": "https://sa-public-files.s3.us-west-2.amazonaws.com/Text+project/text_file_example_1.txt",
366+
"projectId": 167826,
367+
"annotatorEmail": null,
368+
"qaEmail": null,
369+
"lastAction": {
370+
"email": "some.email@gmail.com",
371+
"timestamp": 1636620976450
372+
}
373+
},
374+
"instances": [{
375+
"start": 253,
376+
"end": 593,
377+
"classId": 1,
378+
"createdAt": null,
379+
"createdBy": {
380+
"email": "some.email@gmail.com",
381+
"role": "Admin"
382+
},
383+
"updatedAt": null,
384+
"updatedBy": {
385+
"email": "some.email@gmail.com",
386+
"role": "Admin"
387+
},
388+
"attributes": [],
389+
"creationType": "Manual",
390+
"className": "vid"
391+
}],
392+
"tags": [],
393+
"freeText": ""
394+
}
395+
'''
396+
)
397+
self.assertTrue(sa.validate_annotations("Document", os.path.join(self.vector_folder_path,
398+
f"{tmpdir_name}/test_validate_document_annotation_with_null_created_at.json")))
399+

0 commit comments

Comments
 (0)