Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
43 changes: 24 additions & 19 deletions geoapps_utils/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
import logging
import sys
import tempfile
import warnings
from abc import ABC, abstractmethod
from copy import copy
from pathlib import Path
Expand Down Expand Up @@ -208,25 +209,29 @@ def collect_input_from_dict(
"""
update = data.copy()
nested_fields: list[str] = []
for field, info in model.model_fields.items():
# Already a BaseModel, no need to nest
if isinstance(update.get(field, None), BaseModel):
continue

if (
isinstance(info.annotation, type)
and not isinstance(info.annotation, GenericAlias)
and issubclass(info.annotation, BaseModel)
):
# Nest and deal with aliases
update = Options.collect_input_from_dict(info.annotation, update)
nested = info.annotation.model_construct(**update).model_dump(
exclude_unset=True
)

if any(nested):
update[field] = nested
nested_fields += nested

with warnings.catch_warnings():
warnings.filterwarnings("ignore", category=UserWarning, module="pydantic")

for field, info in model.model_fields.items():
# Already a BaseModel, no need to nest
if isinstance(update.get(field, None), BaseModel):
continue

if (
isinstance(info.annotation, type)
and not isinstance(info.annotation, GenericAlias)
and issubclass(info.annotation, BaseModel)
):
# Nest and deal with aliases
update = Options.collect_input_from_dict(info.annotation, update)
nested = info.annotation.model_construct(**update).model_dump(
exclude_unset=True
)

if any(nested):
update[field] = nested
nested_fields += nested

for field in nested_fields:
if field in update:
Expand Down