Skip to content

Commit

Permalink
Fix pydantic-dict conversion in pydantic_copy.
Browse files Browse the repository at this point in the history
  • Loading branch information
theferrit32 committed Aug 8, 2023
1 parent 151dc85 commit b4c01cf
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 6 deletions.
7 changes: 3 additions & 4 deletions src/ga4gh/core/_internal/identifiers.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
import logging
import re
from typing import Union, Tuple
from pydantic import BaseModel
from pydantic import BaseModel, RootModel
from canonicaljson import encode_canonical_json

from .digests import sha512t24u
Expand Down Expand Up @@ -167,9 +167,8 @@ def export_pydantic_model(obj, exclude_none=True):
# get_pydantic_root, taking whatever it is. Recursion should terminate fine.
if isinstance(obj, BaseModel):
# try custom root type first, if not, assume it's a normal class
obj2 = get_pydantic_root(obj)
if obj2 != obj:
obj = obj2
if isinstance(obj, RootModel):
obj = get_pydantic_root(obj)
else:
obj = obj.model_dump(exclude_none=exclude_none)
return obj
Expand Down
4 changes: 2 additions & 2 deletions src/ga4gh/core/_internal/pydantic.py
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,6 @@ def pydantic_copy(obj: BaseModel) -> BaseModel:

# Treat RootModel differently, it's a thin wrapper of another object, has no fields
if issubclass(pydantic_class, RootModel):
return pydantic_class.model_construct(obj.model_dump())
return pydantic_class(obj.model_dump())
else:
return pydantic_class.model_construct(**obj.model_dump())
return pydantic_class(**obj.model_dump())

0 comments on commit b4c01cf

Please sign in to comment.