Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Exclude related_observables_count from model_dump_json in save method #1134

Merged
merged 2 commits into from
Sep 10, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 8 additions & 4 deletions core/database_arango.py
Original file line number Diff line number Diff line change
Expand Up @@ -250,13 +250,17 @@ def save(
Returns:
The created Yeti object.
"""
doc_dict = self.model_dump(exclude_unset=True, exclude=["tags"])
exclude = ["tags"] + self._exclude_overwrite
doc_dict = self.model_dump(exclude_unset=True, exclude=exclude)
if doc_dict.get("id") is not None:
result = self._update(self.model_dump_json(exclude=["tags"]))
exclude = ["tags"] + self._exclude_overwrite
result = self._update(self.model_dump_json(exclude=exclude))
else:
result = self._insert(self.model_dump_json(exclude=["tags", "id"]))
exclude = ["tags", "id"] + self._exclude_overwrite
result = self._insert(self.model_dump_json(exclude=exclude))
if not result:
result = self._update(self.model_dump_json(exclude=exclude_overwrite))
exclude = exclude_overwrite + self._exclude_overwrite
result = self._update(self.model_dump_json(exclude=exclude))
yeti_object = self.__class__(**result)
# TODO: Override this if we decide to implement YetiTagModel
if hasattr(self, "tags"):
Expand Down
1 change: 1 addition & 0 deletions core/schemas/entity.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ class EntityType(str, Enum):


class Entity(YetiTagModel, database_arango.ArangoYetiConnector):
_exclude_overwrite: list[str] = ["related_observables_count"]
_collection_name: ClassVar[str] = "entities"
_type_filter: ClassVar[str] = ""
_root_type: Literal["entity"] = "entity"
Expand Down
2 changes: 2 additions & 0 deletions core/schemas/graph.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ class GraphFilter(BaseModel):
# Relationship and TagRelationship do not inherit from YetiModel
# because they represent and id in the form of collection_name/id
class Relationship(BaseModel, database_arango.ArangoYetiConnector):
_exclude_overwrite: list[str] = list()
_collection_name: ClassVar[str] = "links"
_type_filter: ClassVar[str | None] = None
__id: str | None = None
Expand Down Expand Up @@ -44,6 +45,7 @@ def load(cls, object: dict):


class TagRelationship(BaseModel, database_arango.ArangoYetiConnector):
_exclude_overwrite: list[str] = list()
_collection_name: ClassVar[str] = "tagged"
_type_filter: None = None
__id: str | None = None
Expand Down
1 change: 1 addition & 0 deletions core/schemas/model.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@


class YetiModel(BaseModel):
_exclude_overwrite: list[str] = list()
__id: str | None = None

def __init__(self, **data):
Expand Down
Loading