Skip to content
Open
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
565 changes: 565 additions & 0 deletions docs/tutorials/pydantic-guide.md

Large diffs are not rendered by default.

4 changes: 4 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,10 @@ typeguard = "^4.0.0"
tqdm = "*"
click = ">=8.0"
shed = "*"
pydantic = { version = ">=2.7,<3", optional = true }

[tool.poetry.extras]
pydantic = ["pydantic"]

[tool.poetry.group.dev.dependencies]
pytest = ">= 3"
Expand Down
12 changes: 8 additions & 4 deletions terminusdb_client/client/Client.py
Original file line number Diff line number Diff line change
Expand Up @@ -1422,7 +1422,7 @@ def _conv_to_dict(self, obj):
return obj.to_dict()
elif hasattr(obj, "_to_dict"):
if hasattr(obj, "_isinstance") and obj._isinstance:
if hasattr(obj.__class__, "_subdocument"):
if getattr(obj.__class__, "_subdocument", None) is not None:
raise ValueError("Subdocument cannot be added directly")
(d, refs) = obj._obj_to_dict()
# merge all refs
Expand Down Expand Up @@ -1453,7 +1453,7 @@ def _convert_document(self, document, graph_type):
"Inserting Schema object into non-schema graph."
)
item_dict = self._conv_to_dict(item)
if hasattr(item, "_capture"):
if getattr(item, "_capture", None) is not None:
seen[item._capture] = item_dict
else:
if isinstance(item_dict, list):
Expand Down Expand Up @@ -1582,7 +1582,9 @@ def insert_document(
result = json.loads(_finish_response(result))
if isinstance(all_docs, list):
for idx, item in enumerate(all_docs):
if hasattr(item, "_obj_to_dict") and not hasattr(item, "_backend_id"):
if hasattr(item, "_obj_to_dict") and getattr(
item, "_backend_id", None
) is None:
item._backend_id = result[idx]
return result

Expand Down Expand Up @@ -1668,7 +1670,9 @@ def replace_document(
result = json.loads(_finish_response(result))
if isinstance(all_docs, list):
for idx, item in enumerate(all_docs):
if hasattr(item, "_obj_to_dict") and not hasattr(item, "_backend_id"):
if hasattr(item, "_obj_to_dict") and getattr(
item, "_backend_id", None
) is None:
item._backend_id = result[idx].removeprefix(
"terminusdb:///data/"
)
Expand Down
Loading
Loading