Skip to content

Commit bbe9683

Browse files
BenjaminCharmesml-evs
authored andcommitted
Update various blocks for pydantic v2
1 parent 701dd4c commit bbe9683

File tree

3 files changed

+10
-8
lines changed

3 files changed

+10
-8
lines changed

pydatalab/src/pydatalab/apps/chat/blocks.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -205,8 +205,8 @@ def _prepare_item_json_for_chat(self, item_id: str, item_data: dict | None = Non
205205
item_model.blocks_obj = {
206206
k: block for k, block in item_model.blocks_obj.items() if block.blocktype != "chat"
207207
}
208-
item_data = item_model.dict(exclude_none=True, exclude_unset=True)
209-
item_data["type"] = item_model.type
208+
item_info = item_model.model_dump(exclude_none=True, exclude_unset=True)
209+
item_info["type"] = item_model.type
210210

211211
# strip irrelevant or large fields
212212
item_filenames = {

pydatalab/src/pydatalab/apps/xrd/blocks.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -263,7 +263,7 @@ def generate_xrd_plot(self, filenames: list[str | Path] | None = None) -> None:
263263
except Exception as exc:
264264
warnings.warn(f"Could not parse file {f['location']} as XRD data. Error: {exc}")
265265
continue
266-
peak_information[str(f["immutable_id"])] = PeakInformation(**peak_data).dict()
266+
peak_information[str(f["immutable_id"])] = PeakInformation(**peak_data).model_dump()
267267
pattern_df["normalized intensity (staggered)"] += ind
268268
pattern_dfs.append(pattern_df)
269269

@@ -292,7 +292,9 @@ def generate_xrd_plot(self, filenames: list[str | Path] | None = None) -> None:
292292
peak_model = PeakInformation(**peak_data)
293293
if "computed" not in self.data:
294294
self.data["computed"] = {"peak_data": {}}
295-
self.data["computed"]["peak_data"][str(file_info["immutable_id"])] = peak_model.dict()
295+
self.data["computed"]["peak_data"][str(file_info["immutable_id"])] = (
296+
peak_model.model_dump()
297+
)
296298
pattern_dfs = [pattern_df]
297299

298300
else:
@@ -311,7 +313,7 @@ def generate_xrd_plot(self, filenames: list[str | Path] | None = None) -> None:
311313
peak_model = PeakInformation(**peak_data)
312314
if "computed" not in self.data:
313315
self.data["computed"] = {"peak_data": {}}
314-
self.data["computed"]["peak_data"][f] = peak_model.dict()
316+
self.data["computed"]["peak_data"][f] = peak_model.model_dump()
315317
pattern_dfs = [pattern_df]
316318

317319
if pattern_dfs:

pydatalab/src/pydatalab/blocks/base.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -201,7 +201,7 @@ def to_db(self) -> dict:
201201
block, ready to be input into mongodb"""
202202

203203
LOGGER.debug("Casting block %s to database object.", self.__class__.__name__)
204-
return self.block_db_model(**self.data).dict(
204+
return self.block_db_model(**self.data).model_dump(
205205
exclude={"bokeh_plot_data", "b64_encoded_image"}, exclude_unset=True
206206
)
207207

@@ -245,7 +245,7 @@ def to_web(self) -> dict[str, Any]:
245245
else:
246246
self.data.pop("warnings", None)
247247

248-
return self.block_db_model(**self.data).dict(exclude_unset=True, exclude_none=True)
248+
return self.block_db_model(**self.data).model_dump(exclude_unset=True, exclude_none=True)
249249

250250
def process_events(self, events: list[dict] | dict):
251251
"""Handle any supported events passed to the block."""
@@ -333,7 +333,7 @@ def update_from_web(self, data: dict):
333333
self.__class__.__name__,
334334
)
335335
self.data.update(
336-
self.block_db_model(**data).dict(
336+
self.block_db_model(**data).model_dump(
337337
exclude={"computed", "metadata", "bokeh_plot_data", "b64_encoded_image"},
338338
exclude_unset=True,
339339
)

0 commit comments

Comments
 (0)