Skip to content

Commit a2c0d64

Browse files
author
Jesse Claven
authored
refactor(pydantic): Remaining migrations for deprecated functions (#1757)
These were missed in #1748.
1 parent bcd8e7f commit a2c0d64

File tree

8 files changed

+101
-105
lines changed

8 files changed

+101
-105
lines changed

docs/examples/content-type/README.ipynb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -203,7 +203,7 @@
203203
"\n",
204204
"response = requests.post(\n",
205205
" \"http://localhost:8080/v2/models/content-type-example/infer\",\n",
206-
" json=payload.dict()\n",
206+
" json=payload.model_dump()\n",
207207
")\n",
208208
"\n",
209209
"response_payload = InferenceResponse.parse_raw(response.text)\n",

docs/examples/content-type/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -146,7 +146,7 @@ payload = InferenceRequest(
146146

147147
response = requests.post(
148148
"http://localhost:8080/v2/models/content-type-example/infer",
149-
json=payload.dict()
149+
json=payload.model_dump()
150150
)
151151

152152
response_payload = InferenceResponse.parse_raw(response.text)

docs/examples/custom/README.ipynb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -311,7 +311,7 @@
311311
")\n",
312312
"\n",
313313
"endpoint = \"http://localhost:8080/v2/models/numpyro-divorce/infer\"\n",
314-
"response = requests.post(endpoint, json=inference_request.dict())\n",
314+
"response = requests.post(endpoint, json=inference_request.model_dump())\n",
315315
"\n",
316316
"response.json()"
317317
]
@@ -411,7 +411,7 @@
411411
")\n",
412412
"\n",
413413
"endpoint = \"http://localhost:8080/v2/models/numpyro-divorce/infer\"\n",
414-
"response = requests.post(endpoint, json=inference_request.dict())\n",
414+
"response = requests.post(endpoint, json=inference_request.model_dump())\n",
415415
"\n",
416416
"response.json()"
417417
]

docs/examples/custom/README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -226,7 +226,7 @@ inference_request = InferenceRequest(
226226
)
227227

228228
endpoint = "http://localhost:8080/v2/models/numpyro-divorce/infer"
229-
response = requests.post(endpoint, json=inference_request.dict())
229+
response = requests.post(endpoint, json=inference_request.model_dump())
230230

231231
response.json()
232232
```
@@ -285,7 +285,7 @@ inference_request = InferenceRequest(
285285
)
286286

287287
endpoint = "http://localhost:8080/v2/models/numpyro-divorce/infer"
288-
response = requests.post(endpoint, json=inference_request.dict())
288+
response = requests.post(endpoint, json=inference_request.model_dump())
289289

290290
response.json()
291291
```

docs/getting-started/index.md

Lines changed: 92 additions & 92 deletions
Large diffs are not rendered by default.

docs/user-guide/content-type.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -169,7 +169,7 @@ MLServer) you will need to **convert them to a Python dict or a JSON string**.
169169

170170
Luckily, these classes leverage [Pydantic](https://docs.pydantic.dev/latest/)
171171
under the hood.
172-
Therefore you can just call the `.dict()` or `.json()` method to convert them.
172+
Therefore you can just call the `.model_dump()` or `.model_dump_json()` method to convert them.
173173
Likewise, to read them back from JSON, we can always pass the JSON fields as
174174
kwargs to the class' constructor (or use any of the [other
175175
methods](https://docs.pydantic.dev/latest/usage/models/#model-properties)

tests/repository/test_load.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ def custom_module_settings_path(
2424
# Add modified settings, pointing to local module
2525
model_settings_path = os.path.join(tmp_path, DEFAULT_MODEL_SETTINGS_FILENAME)
2626
with open(model_settings_path, "w") as f:
27-
settings_dict = sum_model_settings.dict()
27+
settings_dict = sum_model_settings.model_dump()
2828
# Point to local module
2929
settings_dict["implementation"] = "fixtures.SumModel"
3030
f.write(json.dumps(settings_dict))

tests/rest/test_codecs.py

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@
2121
"data": [21.0],
2222
"parameters": {
2323
"content_type": NumpyCodec.ContentType,
24-
"headers": None,
2524
},
2625
},
2726
),
@@ -35,7 +34,6 @@
3534
"data": ["\x01\x02"],
3635
"parameters": {
3736
"content_type": NumpyCodec.ContentType,
38-
"headers": None,
3937
},
4038
},
4139
),
@@ -49,7 +47,6 @@
4947
"data": ["hey", "what's", "up"],
5048
"parameters": {
5149
"content_type": StringCodec.ContentType,
52-
"headers": None,
5350
},
5451
},
5552
),
@@ -63,7 +60,6 @@
6360
"data": ["UHl0aG9uIGlzIGZ1bg=="],
6461
"parameters": {
6562
"content_type": Base64Codec.ContentType,
66-
"headers": None,
6763
},
6864
},
6965
),
@@ -73,7 +69,7 @@ def test_encode_output_tensor(decoded: Any, codec: InputCodec, expected: dict):
7369
# Serialise response into final output bytes
7470
payload = codec.encode_output(name="output-0", payload=decoded)
7571
response = Response(content=None)
76-
rendered_as_bytes = response.render(payload.dict())
72+
rendered_as_bytes = response.render(payload.model_dump())
7773

7874
# Decode response back into JSON and check if it matches the expected one
7975
rendered = rendered_as_bytes.decode("utf8")

0 commit comments

Comments
 (0)