title: fb-hydra: How to implement 2 nested structured configs?
body: <p>I have 2 sub configs and one master(?) config that having those sub configs. I designed configs like below:</p>
  <pre class="lang-py prettyprint-override"><code>from dataclasses import dataclass, field
  
  import hydra
  from hydra.core.config_store import ConfigStore
  from omegaconf import MISSING, DictConfig
  
  from typing import Any, List
  
  @dataclass
  class DBConfig:
      host: str = &quot;localhost&quot;
      driver: str = MISSING
      port: int = MISSING
  
  
  @dataclass
  class MySQLConfig(DBConfig):
      driver: str = &quot;mysql&quot;
      port: int = 3306
  
  
  @dataclass
  class PostGreSQLConfig(DBConfig):
      driver: str = &quot;postgresql&quot;
      port: int = 5432
      timeout: int = 10
  
  
  @dataclass
  class ConnectionConfig:
      target: str = &quot;app.my_class.MyClass&quot;
      params: DBConfig = MISSING
      defaults: List[Any] = field(
          default_factory=lambda: [
              {
                  &quot;params&quot;: &quot;mysql&quot;,      # I'd like to set mysql as a default
              }
          ]
      )
  
  
  
  @dataclass
  class AConfig:
      name: str = &quot;foo&quot;
  
  
  @dataclass
  class BConfig(AConfig):
      age: int = 10
  
  
  @dataclass
  class CConfig(AConfig):
      age: int = 20
  
  
  @dataclass
  class SomeOtherConfig:
      target: str = &quot;app.my_class.MyClass2&quot;
      params: AConfig = MISSING
      defaults: List[Any] = field(
          default_factory=lambda: [
              {
                  &quot;params&quot;: &quot;bconfig&quot;,   # I'd like to set bconfig as a default
              }
          ]
      )
  
  
  
  @dataclass
  class Config:
      db_connection: ConnectionConfig = ConnectionConfig()
      some_other: SomeOtherConfig = SomeOtherConfig()
  
  
  @hydra.main(config_name=&quot;config&quot;)
  def my_app(cfg: DictConfig) -&gt; None:
      print(cfg.pretty())
      # connection = hydra.utils.instantiate(cfg)
      # print(connection)
  
  
  if __name__ == &quot;__main__&quot;:
      cs = ConfigStore.instance()
      cs.store(
          name=&quot;config&quot;,
          node=Config,
      )
      cs.store(group=&quot;params&quot;, name=&quot;mysql&quot;, node=MySQLConfig)
      cs.store(group=&quot;params&quot;, name=&quot;postgresql&quot;, node=PostGreSQLConfig)
  
      cs.store(group=&quot;params&quot;, name=&quot;bconfig&quot;, node=BConfig)
      cs.store(group=&quot;params&quot;, name=&quot;cconfig&quot;, node=CConfig)
  
      my_app()
  
  </code></pre>
  <p>What I expected when I run program without any options:</p>
  <pre class="lang-yaml prettyprint-override"><code>db_connection:
      target: app.my_class.MyClass
      params:   
          host: localhost
          driver: mysql
          port: 3306   
  
  some_other:
      target: app.my_class.MyClass2
      params:
          name: &quot;foo&quot;
          age: 10
  </code></pre>
  <p>But the result:</p>
  <pre class="lang-yaml prettyprint-override"><code>db_connection:
      target: app.my_class.MyClass
      params: ???
      defaults:
      - params: mysql
  some_other:
      target: app.my_class.MyClass2
      params: ???
      defaults:
      - params: bconfig
  </code></pre>