Repository: dask/dask

Issue:
keyerror in dask.config.rename when working with distributed
calling `dask-worker` using `dask==1.2.2`, `distributed==1.28.1`, I get the following error:

`Traceback (most recent call last): File "/opt/conda/envs/worker/bin/dask-worker", line 7, in <module> from distributed.cli.dask_worker import go File "/opt/conda/envs/worker/lib/python3.6/site-packages/distributed/__init__.py", line 3, in <module> from . import config File "/opt/conda/envs/worker/lib/python3.6/site-packages/distributed/config.py", line 55, in <module> dask.config.rename(aliases) File "/opt/conda/envs/worker/lib/python3.6/site-packages/dask/config.py", line 451, in rename del config[k] # TODO: support nested keys KeyError: 'tick-maximum-delay'`

It looks like this was introduced by #4742 when `dask.config.rename` was not properly adjusted, so that it can run into these KeyErrors. Current state of the function:

```def rename(aliases, config=config):
    """ Rename old keys to new keys
    This helps migrate older configuration versions over time
    """
    old = []
    new = {}
    for o, n in aliases.items():
        value = get(o, None, config=config)
        if value is not None:
            old.append(o)
            new[n] = value

    for k in old:
        del config[k]  # TODO: support nested keys

    set(new, config=config)
```

Suggest changing the 3rd to last line to `del config[canonical_name(k, config)]`. Will file an appropriate PR.

Discussion:
mrocklin: Thanks for the fix @bolliger32 !  

Do you have any thoughts on what a small test would be for this change?  It would be good to have such a test to make sure that your work doesn't get reverted in the future by some careless change.
bolliger32: Ah good call! Will think something up and push it. Thanks for working w/ a first-timer.
bolliger32: ok @mrocklin just needed a tiny change to an existing test and I think we're good.

Patch:
diff --git a/dask/config.py b/dask/config.py
index 3785e6f98..918e1cb92 100644
--- a/dask/config.py
+++ b/dask/config.py
@@ -448,7 +448,7 @@ def rename(aliases, config=config):
             new[n] = value
 
     for k in old:
-        del config[k]  # TODO: support nested keys
+        del config[canonical_name(k, config)]  # TODO: support nested keys
 
     set(new, config=config)
 


Test patch:
diff --git a/dask/tests/test_config.py b/dask/tests/test_config.py
index 1f6f4f891..a5d7a33d0 100644
--- a/dask/tests/test_config.py
+++ b/dask/tests/test_config.py
@@ -318,7 +318,7 @@ def test_ensure_file_defaults_to_DASK_CONFIG_directory(tmpdir):
 
 
 def test_rename():
-    aliases = {'foo-bar': 'foo.bar'}
+    aliases = {'foo_bar': 'foo.bar'}
     config = {'foo-bar': 123}
     rename(aliases, config=config)
     assert config == {'foo': {'bar': 123}}