Skip to content

Commit

Permalink
Add created_at to our models
Browse files Browse the repository at this point in the history
  • Loading branch information
scosman committed Sep 11, 2024
1 parent 89bf6b9 commit 0d1fae7
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 0 deletions.
2 changes: 2 additions & 0 deletions libs/core/kiln_ai/datamodel/basemodel.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import uuid
from abc import ABCMeta, abstractmethod
from builtins import classmethod
from datetime import datetime
from pathlib import Path
from typing import Optional, Self, Type, TypeVar

Expand Down Expand Up @@ -30,6 +31,7 @@ class KilnBaseModel(BaseModel):

v: int = 1 # schema_version
path: Optional[Path] = Field(default=None, exclude=True)
created_at: datetime = Field(default_factory=datetime.now)

@computed_field()
def model_type(self) -> str:
Expand Down
9 changes: 9 additions & 0 deletions libs/core/kiln_ai/datamodel/test_basemodel.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import datetime
import json
from pathlib import Path
from typing import Optional
Expand Down Expand Up @@ -72,6 +73,14 @@ def test_type_name():
assert model.model_type == "kiln_base_model"


def test_created_at():
model = KilnBaseModel()
assert model.created_at is not None
# Check it's within 2 seconds of now
now = datetime.datetime.now()
assert abs((model.created_at - now).total_seconds()) < 2


# Instance of the parented model for abstract methods
class NamedParentedModel(KilnParentedModel):
@classmethod
Expand Down

0 comments on commit 0d1fae7

Please sign in to comment.