Skip to content

Commit 1cf79a9

Browse files
committed
fix: add check for not None Resource check_all_values validator
1 parent 9d2a125 commit 1cf79a9

File tree

3 files changed

+8
-4
lines changed

3 files changed

+8
-4
lines changed

jsonapi_pydantic/__init__.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
from jsonapi_pydantic import constants, v1_0
22

3-
__version__ = "0.1.2"
3+
__version__ = "0.1.3"
44

55
__all__ = ["constants", "v1_0"]

jsonapi_pydantic/v1_0/resource/resource.py

+6-2
Original file line numberDiff line numberDiff line change
@@ -23,10 +23,14 @@ class Resource(BaseModel):
2323

2424
@root_validator
2525
def check_all_values(cls, values: dict) -> dict:
26+
attributes, relationships = values.get("attributes"), values.get("relationships")
27+
if not attributes and not relationships:
28+
return values
29+
2630
# More about these restrictions: https://jsonapi.org/format/#document-resource-object-fields
2731
try:
28-
attributes = dict(values.get("attributes"))
29-
relationships = dict(values.get("relationships"))
32+
attributes = dict(attributes) if attributes else attributes
33+
relationships = dict(relationships) if relationships else relationships
3034
except (ValueError, TypeError):
3135
raise ValueError("Attributes and relationships must be json objects.")
3236

pyproject.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[tool.poetry]
22
name = "jsonapi-pydantic"
3-
version = "0.1.2"
3+
version = "0.1.3"
44
description = "JSON:API implementation with pydantic."
55

66
authors = ["impocode <[email protected]>"]

0 commit comments

Comments
 (0)