Skip to content
This repository was archived by the owner on Jan 21, 2023. It is now read-only.

Commit 464c090

Browse files
committed
refactor: move serialization arguments to BaseModel
1 parent a497bb6 commit 464c090

File tree

2 files changed

+16
-5
lines changed

2 files changed

+16
-5
lines changed

src/structurizr/api/structurizr_client.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -158,7 +158,7 @@ def put_workspace(self, workspace: Workspace) -> None:
158158
ws_io.last_modified_date = datetime.now(timezone.utc)
159159
ws_io.last_modified_agent = self.agent
160160
ws_io.last_modified_user = self.user
161-
workspace_json = ws_io.json(by_alias=True, exclude_none=True, exclude_defaults=False)
161+
workspace_json = ws_io.json()
162162
logger.debug(workspace_json)
163163
request = self._client.build_request(
164164
"PUT", self._workspace_url, data=workspace_json

src/structurizr/base_model.py

+15-4
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,12 @@ class Config:
3333
orm_mode = True
3434

3535
def dict(
36-
self, *, by_alias: bool = True, exclude_defaults: bool = True, **kwargs
36+
self,
37+
*,
38+
by_alias: bool = True,
39+
exclude_defaults: bool = False,
40+
exclude_none: bool = True,
41+
**kwargs
3742
) -> dict:
3843
"""
3944
Serialize the model using custom settings.
@@ -42,8 +47,11 @@ def dict(
4247
by_alias (bool, optional): Whether to create serialized field names by
4348
their alias (default `True`).
4449
exclude_defaults (bool, optional): Whether to exclude fields that are equal
45-
to their default value from being serialized (default `True`).
46-
**kwargs:
50+
to their default value from being serialized (default `False`).
51+
exclude_none (bool, optional): Whether to exclude keys with `None` values
52+
entirely (default `True`).
53+
**kwargs: Further keyword arguments are passed to the pydantic super method
54+
`.dict`.
4755
4856
Returns:
4957
dict: The serialized model as a (nested) dictionary.
@@ -53,7 +61,10 @@ def dict(
5361
5462
"""
5563
return super().dict(
56-
by_alias=by_alias, exclude_defaults=exclude_defaults, **kwargs
64+
by_alias=by_alias,
65+
exclude_defaults=exclude_defaults,
66+
exclude_none=exclude_none,
67+
**kwargs
5768
)
5869

5970
def json(

0 commit comments

Comments
 (0)