Skip to content

Commit

Permalink
fix: add check for not None Resource check_all_values validator
Browse files Browse the repository at this point in the history
  • Loading branch information
impocode committed Oct 16, 2022
1 parent 9d2a125 commit 1cf79a9
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 4 deletions.
2 changes: 1 addition & 1 deletion jsonapi_pydantic/__init__.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
from jsonapi_pydantic import constants, v1_0

__version__ = "0.1.2"
__version__ = "0.1.3"

__all__ = ["constants", "v1_0"]
8 changes: 6 additions & 2 deletions jsonapi_pydantic/v1_0/resource/resource.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,14 @@ class Resource(BaseModel):

@root_validator
def check_all_values(cls, values: dict) -> dict:
attributes, relationships = values.get("attributes"), values.get("relationships")
if not attributes and not relationships:
return values

# More about these restrictions: https://jsonapi.org/format/#document-resource-object-fields
try:
attributes = dict(values.get("attributes"))
relationships = dict(values.get("relationships"))
attributes = dict(attributes) if attributes else attributes
relationships = dict(relationships) if relationships else relationships
except (ValueError, TypeError):
raise ValueError("Attributes and relationships must be json objects.")

Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[tool.poetry]
name = "jsonapi-pydantic"
version = "0.1.2"
version = "0.1.3"
description = "JSON:API implementation with pydantic."

authors = ["impocode <[email protected]>"]
Expand Down

0 comments on commit 1cf79a9

Please sign in to comment.