Repository: kedro-org/kedro
Pull request: Remove outdated credentials.yml warning
Signed-off-by: Ahdra Merali <ahdra.merali@quantumblack.com>

## Description

Fixes #1952 

**Note:** Tests for credentials handling live in `test_data_catalog.py`

<!-- Why was this PR created? -->

## Development notes
<!-- What have you changed, and how has this been tested? -->

## Checklist

- [ ] Read the [contributing](https://github.com/kedro-org/kedro/blob/main/CONTRIBUTING.md) guidelines
- [x] Opened this PR as a 'Draft Pull Request' if it is work-in-progress
- [ ] Updated the documentation to reflect the code changes
- [ ] Added a description of this change in the [`RELEASE.md`](https://github.com/kedro-org/kedro/blob/main/RELEASE.md) file
- [ ] Added tests to cover my changes


<a href="https://gitpod.io/#https://github.com/kedro-org/kedro/pull/2073"><img src="https://gitpod.io/button/open-in-gitpod.svg"/></a>



Problem statement:
Remove/change log level for "Credentials not found in your Kedro project config"
## Description
When getting the credentials in the KedroContext, we specifically look for the `credentials` file. If a project doesn't make use of this file a warning log will be thrown saying "Credentials not found in your Kedro project config". Not all users use the credentials file and so this warning isn't applicable. 

## Context
We're adding functionality to allow users to have credentials in environment variables (which is currently also possible with the `TemplatedConfigLoader`), which makes this error irrelevant.

Hints from issue discussion:

Commit message: Remove warning and add tests

Signed-off-by: Ahdra Merali <ahdra.merali@quantumblack.com>

Patch to review:
diff --git a/kedro/framework/context/context.py b/kedro/framework/context/context.py
index df7ad635ab..936758bb21 100644
--- a/kedro/framework/context/context.py
+++ b/kedro/framework/context/context.py
@@ -335,9 +335,8 @@ def _get_config_credentials(self) -> Dict[str, Any]:
         """Getter for credentials specified in credentials directory."""
         try:
             conf_creds = self.config_loader["credentials"]
-        except MissingConfigException as exc:
-            warn(f"Credentials not found in your Kedro project config.\n{str(exc)}")
-            conf_creds = {}
+        except MissingConfigException:
+            conf_creds = None
         return conf_creds
 
 
diff --git a/kedro/io/data_catalog.py b/kedro/io/data_catalog.py
index 80886cabfa..867a522516 100644
--- a/kedro/io/data_catalog.py
+++ b/kedro/io/data_catalog.py
@@ -11,6 +11,7 @@
 from collections import defaultdict
 from typing import Any, Dict, List, Optional, Set, Type, Union
 
+from kedro.config.abstract_config import MissingConfigException
 from kedro.io.core import (
     AbstractDataSet,
     AbstractVersionedDataSet,
@@ -42,10 +43,16 @@ def _get_credentials(
     Raises:
         KeyError: When a data set with the given name has not yet been
             registered.
+        MissingConfigError: When no credentials file is found in the
+            project.
 
     """
     try:
         return credentials[credentials_name]
+    except TypeError as exc:
+        raise MissingConfigException(
+            f"Credentials not found in your Kedro project config."
+        )
     except KeyError as exc:
         raise KeyError(
             f"Unable to find credentials '{credentials_name}': check your data "
@@ -256,7 +263,7 @@ class to be loaded is specified with the key ``type`` and their
         """
         data_sets = {}
         catalog = copy.deepcopy(catalog) or {}
-        credentials = copy.deepcopy(credentials) or {}
+        credentials = copy.deepcopy(credentials)
         save_version = save_version or generate_timestamp()
         load_versions = copy.deepcopy(load_versions) or {}
 
diff --git a/tests/framework/context/test_context.py b/tests/framework/context/test_context.py
index 7bece973cc..1ea029f51a 100644
--- a/tests/framework/context/test_context.py
+++ b/tests/framework/context/test_context.py
@@ -97,6 +97,7 @@ def local_config(tmp_path):
             "filepath": boats_filepath,
             "versioned": True,
             "layer": "raw",
+            "credentials": "cred_name",
         },
         "horses": {
             "type": "pandas.CSVDataSet",
@@ -120,9 +121,10 @@ def prepare_project_dir(tmp_path, base_config, local_config, env):
     parameters = tmp_path / "conf" / "base" / "parameters.json"
     db_config_path = tmp_path / "conf" / "base" / "db.ini"
     project_parameters = {"param1": 1, "param2": 2, "param3": {"param4": 3}}
+    project_credentials = {"cred_name": {"key": "secret"}}
     _write_yaml(proj_catalog, base_config)
     _write_yaml(env_catalog, local_config)
-    _write_yaml(env_credentials, local_config)
+    _write_yaml(env_credentials, project_credentials)
     _write_json(parameters, project_parameters)
     _write_dummy_ini(db_config_path)
 
@@ -297,6 +299,23 @@ def test_missing_parameters(self, tmp_path, dummy_context):
         with pytest.warns(UserWarning, match=re.escape(pattern)):
             _ = dummy_context.catalog
 
+    def test_empty_credentials(self, dummy_context):
+
+        env_credentials = (
+            dummy_context.project_path / "conf" / "local" / "credentials.yml"
+        )
+        empty_credentials = {}
+        _write_yaml(env_credentials, empty_credentials)
+        credentials = "cred_name"
+
+        pattern = (
+            f"Unable to find credentials '{credentials}': check your data catalog and credentials configuration. "
+            f"See https://kedro.readthedocs.io/en/stable/kedro.io.DataCatalog.html for an example."
+        )
+
+        with pytest.raises(KeyError, match=re.escape(pattern)):
+            _ = dummy_context.catalog
+
     def test_missing_credentials(self, dummy_context):
         env_credentials = (
             dummy_context.project_path / "conf" / "local" / "credentials.yml"
@@ -304,7 +323,7 @@ def test_missing_credentials(self, dummy_context):
         env_credentials.unlink()
 
         pattern = "Credentials not found in your Kedro project config."
-        with pytest.warns(UserWarning, match=re.escape(pattern)):
+        with pytest.raises(MissingConfigException, match=re.escape(pattern)):
             _ = dummy_context.catalog
 
 


Code review comments:
diff_hunk: @@ -42,10 +43,16 @@ def _get_credentials(
     Raises:
         KeyError: When a data set with the given name has not yet been
             registered.
+        MissingConfigError: When no credentials file is found in the
+            project.
 
     """
     try:
         return credentials[credentials_name]
+    except TypeError as exc:
+        raise MissingConfigException(
+            f"Credentials not found in your Kedro project config."
+        )
path: kedro/io/data_catalog.py
text: @user1:
Would it be better if this moved before the `try` block? When this function is called but `credentials` is None then it indicates it doesn't have the configuration.