Skip to content

Commit

Permalink
[bugfix] Fix pydantic v1/v2 compatible model_dump method (backport #5388
Browse files Browse the repository at this point in the history
) (#5396)

[bugfix] Fix pydantic v1/v2 compatible model_dump method (#5388)

(cherry picked from commit 67b2977)

Co-authored-by: Hailin Wang <[email protected]>
  • Loading branch information
mergify[bot] and haiiliin authored Nov 23, 2023
1 parent 437d6a0 commit c4ceba6
Showing 1 changed file with 12 additions and 4 deletions.
16 changes: 12 additions & 4 deletions src/abqpy/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,20 @@

import ast
import os
from typing import Optional
from typing import Any, Optional

from pydantic import BaseModel


class AbaqusCAEConfig(BaseModel):
class CompatibleBaseModel(BaseModel):
def model_dump(self, **kwargs) -> dict[str, Any]:
try:
return super().model_dump(**kwargs)
except AttributeError:
return super().dict(**kwargs)


class AbaqusCAEConfig(CompatibleBaseModel):
database: Optional[str] = None
replay: Optional[str] = None
recover: Optional[str] = None
Expand All @@ -21,12 +29,12 @@ class AbaqusCAEConfig(BaseModel):
guiRecord: Optional[bool] = None


class AbaqusPythonConfig(BaseModel):
class AbaqusPythonConfig(CompatibleBaseModel):
sim: Optional[str] = None
log: Optional[str] = None


class AbaqusConfig(BaseModel):
class AbaqusConfig(CompatibleBaseModel):
cae: AbaqusCAEConfig
python: AbaqusPythonConfig

Expand Down

0 comments on commit c4ceba6

Please sign in to comment.