Skip to content

Commit

Permalink
robot-server: json -> .model_dump_json
Browse files Browse the repository at this point in the history
  • Loading branch information
SyntaxColoring committed Dec 17, 2024
1 parent ba9c12c commit 34e4d7e
Show file tree
Hide file tree
Showing 4 changed files with 7 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -219,7 +219,7 @@ def _migrate_data_1_to_2(transaction: sqlalchemy.engine.Connection) -> None:
_legacy_pickle.loads(row.completed_analysis)
)

v2_completed_analysis_as_document = v1_completed_analysis.json(
v2_completed_analysis_as_document = v1_completed_analysis.model_dump_json(
# by_alias and exclude_none should match how
# FastAPI + Pydantic + our customizations serialize these objects
# over the `GET /protocols/:id/analyses/:id` endpoint.
Expand Down
2 changes: 1 addition & 1 deletion robot-server/robot_server/persistence/pydantic.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@

def pydantic_to_json(obj: BaseModel) -> str:
"""Serialize a Pydantic object for storing in the SQL database."""
return obj.json(
return obj.model_dump_json(
# by_alias and exclude_none should match how
# FastAPI + Pydantic + our customizations serialize these objects
by_alias=True,
Expand Down
6 changes: 3 additions & 3 deletions robot-server/robot_server/service/json_api/response.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,13 +61,13 @@ def dict(self, *args: Any, **kwargs: Any) -> Dict[str, Any]:
def model_dump_json(self, *args: Any, **kwargs: Any) -> str:
"""See notes in `.model_dump()`."""
kwargs["exclude_none"] = True
return super().json(*args, **kwargs)
return super().model_dump_json(*args, **kwargs)

@override
def json(self, *args: Any, **kwargs: Any) -> str:
"""See notes in `.model_dump()`."""
kwargs["exclude_none"] = True
return super().json(*args, **kwargs)
return super().model_dump_json(*args, **kwargs)


class SimpleBody(BaseResponseBody, Generic[ResponseDataT]):
Expand Down Expand Up @@ -234,7 +234,7 @@ async def create(

def render(self, content: ResponseBodyT) -> bytes:
"""Render the response body to JSON bytes."""
return content.json().encode(self.charset)
return content.model_dump_json().encode(self.charset)


# TODO(mc, 2021-12-09): remove this model
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ def publish_advise_refetch(
topic: The topic to publish the message on.
"""
message = NotifyRefetchBody.model_construct()
payload = message.json()
payload = message.model_dump_json()
self._client.publish(
topic=topic,
payload=payload,
Expand All @@ -110,7 +110,7 @@ def publish_advise_unsubscribe(
topic: The topic to publish the message on.
"""
message = NotifyUnsubscribeBody.model_construct()
payload = message.json()
payload = message.model_dump_json()
self._client.publish(
topic=topic,
payload=payload,
Expand Down

0 comments on commit 34e4d7e

Please sign in to comment.