How to load a specific catalog item in kedro 0.17.0

Hello,

We were using kedro version 0.15.8 and we were loading one specific item from the catalog this way:

from kedro.context import load_context
get_context().catalog.datasets.__dict__[key]

Now, we are changing to kedro 0.17.0 and trying to load the catalogs datasets the same way(using the framework context):

from kedro.framework.context import load_context
get_context().catalog.datasets.__dict__[key]

And now we get the error:

kedro.framework.context.context.KedroContextError: Expected an instance of ConfigLoader, got NoneType instead.

It’s because the hook register_config_loader from the project it’s not being used by the hook_manager that calls the function.

The project hooks are the defined the following way:

class ProjectHooks:

    @hook_impl

    def register_pipelines(self) -> Dict[str, Pipeline]:

        """Register the project's pipeline.

        Returns:

            A mapping from a pipeline name to a ``Pipeline`` object.

        """

        pm = pre_master.create_pipeline()

        return {

            "pre_master": pm,

            "__default__": pm

        }

    @hook_impl

    def register_config_loader(self, conf_paths: Iterable[str]) -> ConfigLoader:

        return ConfigLoader(conf_paths)

    @hook_impl

    def register_catalog(

        self,

        catalog: Optional[Dict[str, Dict[str, Any]]],

        credentials: Dict[str, Dict[str, Any]],

        load_versions: Dict[str, str],

        save_version: str,

        journal: Journal,

    ) -> DataCatalog:

        return DataCatalog.from_config(

            catalog, credentials, load_versions, save_version, journal

        )

project_hooks = ProjectHooks()

And the settings are called the following way:
“”“Project settings.”""

from price_based_trading.hooks import ProjectHooks


HOOKS = (ProjectHooks(),)

How can we configure that in a way that the hooks are used calling the method load_context(_working_dir).catalog.datasets ?

Best

Hi, I have replied to the SO thread. We can continue there as well but maybe let’s try using the Session and see if it helps? At the bottom of this guide Lifecycle management with KedroSession — Kedro 0.17.0 documentation there is an example to load a specific dataset.

1 Like

Another hunch I have is that maybe you are trying to do this in an IPython notebook and maybe your IPython init script isn’t compatible with Kedro 0.17 somehow. Try generating a new project with kedro new and overwrite the content of your .ipython/profile_default/startup/00-kedro-init.py with content from the same file in the new project.

1 Like

Hello, thanks for the answer, it’s correct, what you point. The only thing that I was missing was to create the KedroSession.

KedroSession.create("name_of_proyect") as session:
    session = get_current_session()
    context = session.load_context()
    kedro_connector = context.catalog.load(key)

Newbie mistake