Chee Ming Siow
04/07/2025, 8:45 AMValueError: Duplicate keys found in ...
?
In my code, have a function that runs before the actual kedro pipeline. I wish to retrieve the config in the function and prioritize the config attributes defined in local env
sample code
###### main.py #####
if __name__ == "__main__":
# Bootstrap the project to make the config loader available
project_path = Path.cwd()
bootstrap_project(project_path)
# Create a Kedro session
with KedroSession.create(project_path=project_path) as session:
# You can now access the catalog, pipeline, etc. from the session
# For example, to run the pipeline:
conf_eda() # <------------- function
session.run()
pass
##### myfunc.py #####
def conf_eda():
project_path = Path.cwd()
conf_path = str(project_path/"conf")
conf_loader = OmegaConfigLoader(
conf_source=conf_path,
)
parameters = conf_loader["parameters"] # <----------- error
print(parameters["model_options"])
##### conf/base/parameters_data_science.yml #####
model_options:
test_size: 100
random_state: 3
##### conf/local/parameters_data_science.yml #####
model_options:
test_size: 300
random_state: 3
Dmitry Sorokin
04/07/2025, 9:32 AMbase
and local
), with values in local
overriding those in base
.
https://docs.kedro.org/en/stable/configuration/configuration_basics.html#configuration-loading
However, if the same key appears more than once within a single environment (e.g., defined in multiple files under conf/base/
), you'll get a ValueError
for duplicate keys.
Could you check if that's the case in your setup?Chee Ming Siow
04/07/2025, 9:59 AMsession.load_context().config_loader
it is working as expected.
with KedroSession.create(project_path=project_path) as session:
# You can now access the catalog, pipeline, etc. from the session
# For example, to run the pipeline:
# Retrieve the config loader from the session
config_loader = session.load_context().config_loader
# Access configurations
parameters = config_loader.get("parameters")
print(parameters) #<------ OK, result is expected
conf_eda() # <------- Not OK, using OmegaConfigLoader()
session.run()
I believe that I passed in the wrong params in my OmegaConfigLoader()
in my function that resulted in ValueError
.Chee Ming Siow
04/07/2025, 10:01 AMDmitry Sorokin
04/07/2025, 10:17 AMconfig_loader = session.load_context().config_loader
conf_eda(config_loader)
Chee Ming Siow
04/07/2025, 10:18 AM