Skip to content

How can I override an element of ListConfig using structured configs? #2558

Answered by Jasha10
dnnspark asked this question in Q&A
Discussion options

You must be logged in to vote

Hi @dnnspark,
Here are a few options:

Option 1: create a new field object:

...
@dataclass
class YourSQLConfig(MySQLConfig):
    defaults: List[Any] = field(default_factory=lambda: ["mysql"])
    host: str = "your_sql"
    ports: ListConfig = field(default_factory=lambda: ListConfig([3306, 3307, 4000]))
...

Option 2: pass an override at the command line:

python app.py db.ports.2=4000

Option 3: Use the oc.dict.values trick (detailed here).

from dataclasses import dataclass, field
from typing import Any, List, Dict
import hydra
from hydra.core.config_store import ConfigStore
from omegaconf import MISSING, OmegaConf, SI

@dataclass
class MySQLConfig:
    host: str = "mysql"
    ports: List[int] 

Replies: 1 comment 1 reply

Comment options

You must be logged in to vote
1 reply
@dnnspark
Comment options

Answer selected by dnnspark
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants