# Buggy code
def _compose_config_from_defaults_list(
    self,
    defaults: List[ResultDefault],
    repo: IConfigRepository,
) -> DictConfig:
    cfg = OmegaConf.create()
    for default in defaults:
        loaded = self._load_single_config(default=default, repo=repo)
        try:
            cfg.merge_with(loaded.config)
        except ValidationError as e:
            raise ConfigCompositionException(
                f"In '{default.config_path}': Validation error while composing config:\n{e}"
            ).with_traceback(sys.exc_info()[2])

    # This is primarily cosmetic
    cfg._metadata.ref_type = cfg._metadata.object_type

    return cfg


# Traceback (ValueError)
$ python test.py --config-name=test1
Traceback (most recent call last):
File "/private/home/shubhamgoel/.conda/envs/py3d-implicit/lib/python3.8/site-packages/hydra/_internal/utils.py", line 212, in run_and_report
return func()
File "/private/home/shubhamgoel/.conda/envs/py3d-implicit/lib/python3.8/site-packages/hydra/_internal/utils.py", line 365, in <lambda>
lambda: hydra.run(
File "/private/home/shubhamgoel/.conda/envs/py3d-implicit/lib/python3.8/site-packages/hydra/_internal/hydra.py", line 101, in run
cfg = self.compose_config(
File "/private/home/shubhamgoel/.conda/envs/py3d-implicit/lib/python3.8/site-packages/hydra/_internal/hydra.py", line 542, in compose_config
cfg = self.config_loader.load_configuration(
File "/private/home/shubhamgoel/.conda/envs/py3d-implicit/lib/python3.8/site-packages/hydra/_internal/config_loader_impl.py", line 150, in load_configuration
return self._load_configuration_impl(
File "/private/home/shubhamgoel/.conda/envs/py3d-implicit/lib/python3.8/site-packages/hydra/_internal/config_loader_impl.py", line 191, in _load_configuration_impl
cfg, composition_trace = self._compose_config_from_defaults_list(
File "/private/home/shubhamgoel/.conda/envs/py3d-implicit/lib/python3.8/site-packages/hydra/_internal/config_loader_impl.py", line 424, in _compose_config_from_defaults_list
merged = OmegaConf.merge(cfg, loaded.config)
File "/private/home/shubhamgoel/.conda/envs/py3d-implicit/lib/python3.8/site-packages/omegaconf/omegaconf.py", line 355, in merge
target.merge_with(*others[1:])
File "/private/home/shubhamgoel/.conda/envs/py3d-implicit/lib/python3.8/site-packages/omegaconf/basecontainer.py", line 427, in merge_with
self._format_and_raise(key=None, value=None, cause=e)
File "/private/home/shubhamgoel/.conda/envs/py3d-implicit/lib/python3.8/site-packages/omegaconf/base.py", line 107, in _format_and_raise
format_and_raise(
File "/private/home/shubhamgoel/.conda/envs/py3d-implicit/lib/python3.8/site-packages/omegaconf/_utils.py", line 678, in format_and_raise
_raise(ex, cause)
File "/private/home/shubhamgoel/.conda/envs/py3d-implicit/lib/python3.8/site-packages/omegaconf/_utils.py", line 588, in _raise
raise ex  # set end OC_CAUSE=1 for full backtrace
ValueError: HydraConfig was not set
full_key: job.config_name
reference_type=Optional[Dict[Union[str, Enum], Any]]
object_type=dict
full_key:
reference_type=Optional[Dict[Union[str, Enum], Any]]
object_type=dict

# Fixed code
def _compose_config_from_defaults_list(
    self,
    defaults: List[ResultDefault],
    repo: IConfigRepository,
) -> DictConfig:
    cfg = OmegaConf.create()
    with flag_override(cfg, "no_deepcopy_set_nodes", True):
        for default in defaults:
            loaded = self._load_single_config(default=default, repo=repo)
            try:
                cfg.merge_with(loaded.config)
            except ValidationError as e:
                raise ConfigCompositionException(
                    f"In '{default.config_path}': Validation error while composing config:\n{e}"
                ).with_traceback(sys.exc_info()[2])

    # This is primarily cosmetic
    cfg._metadata.ref_type = cfg._metadata.object_type

    return cfg