Skip to content

Commit

Permalink
Modify get_dataclass_data to fix omry#830 and omry#831
Browse files Browse the repository at this point in the history
  • Loading branch information
Jasha10 committed Dec 2, 2021
1 parent 321f4d1 commit 3b825ed
Showing 1 changed file with 11 additions and 5 deletions.
16 changes: 11 additions & 5 deletions omegaconf/_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -332,6 +332,7 @@ def get_dataclass_data(

flags = {"allow_objects": allow_objects} if allow_objects is not None else {}
d = {}
is_type = isinstance(obj, type)
obj_type = get_type_of(obj)
dummy_parent = OmegaConf.create({}, flags=flags)
dummy_parent._metadata.object_type = obj_type
Expand All @@ -340,13 +341,18 @@ def get_dataclass_data(
name = field.name
is_optional, type_ = _resolve_optional(resolved_hints[field.name])
type_ = _resolve_forward(type_, obj.__module__)
has_default = field.default != dataclasses.MISSING
has_default_factory = field.default_factory != dataclasses.MISSING # type: ignore

value = getattr(obj, name, MISSING)
if value in (MISSING, dataclasses.MISSING):
if field.default_factory == dataclasses.MISSING: # type: ignore
value = MISSING
else:
if not is_type:
value = getattr(obj, name)
else:
if has_default:
value = field.default
elif has_default_factory:
value = field.default_factory() # type: ignore
else:
value = MISSING

if _is_union(type_):
e = ConfigValueError(
Expand Down

0 comments on commit 3b825ed

Please sign in to comment.