Repository: conda/conda

Issue:
KeyError when removing package
We see the following KeyError when trying to remove a conda package, we've just upgraded from using conda 4.1.3 to 4.3.4.
The last version that seems to work is 4.1.12, however 4.2.x may work as well for this issue, but it cannot get into this point due to unrelated (http, condahttp, etc) errors.

Full details are in the following travis log: https://travis-ci.org/astropy/package-template/jobs/192393894

Test runs for checking which one is the latest working version are here:
https://travis-ci.org/bsipocz/package-template/builds/192422476


```
Current conda install:

               platform : linux-64

          conda version : 4.3.4

       conda is private : False

      conda-env version : 4.3.4

    conda-build version : not installed

         python version : 2.7.13.final.0

       requests version : 2.12.4

       root environment : /home/travis/miniconda  (writable)

    default environment : /home/travis/miniconda/envs/test

       envs directories : /home/travis/miniconda/envs

          package cache : /home/travis/miniconda/pkgs

           channel URLs : https://conda.anaconda.org/astropy-ci-extras astropy/linux-64

                          https://conda.anaconda.org/astropy-ci-extras astropy/noarch

                          https://conda.anaconda.org/astropy/linux-64

                          https://conda.anaconda.org/astropy/noarch

                          https://conda.anaconda.org/astropy-ci-extras/linux-64

                          https://conda.anaconda.org/astropy-ci-extras/noarch

                          https://repo.continuum.io/pkgs/free/linux-64

                          https://repo.continuum.io/pkgs/free/noarch

                          https://repo.continuum.io/pkgs/r/linux-64

                          https://repo.continuum.io/pkgs/r/noarch

                          https://repo.continuum.io/pkgs/pro/linux-64

                          https://repo.continuum.io/pkgs/pro/noarch

            config file : /home/travis/.condarc

           offline mode : False

             user-agent : conda/4.3.4 requests/2.12.4 CPython/2.7.13 Linux/4.8.12-040812-generic debian/wheezy/sid glibc/2.15

                UID:GID : 1000:1000

`$ /home/travis/miniconda/envs/test/bin/conda remove astropy --force`

    Traceback (most recent call last):

      File "/home/travis/miniconda/lib/python2.7/site-packages/conda/exceptions.py", line 617, in conda_exception_handler

        return_value = func(*args, **kwargs)

      File "/home/travis/miniconda/lib/python2.7/site-packages/conda/cli/main.py", line 158, in _main

        exit_code = args.func(args, p)

      File "/home/travis/miniconda/lib/python2.7/site-packages/conda/cli/main_remove.py", line 164, in execute

        pinned=args.pinned))

      File "/home/travis/miniconda/lib/python2.7/site-packages/conda/plan.py", line 776, in remove_actions

        if pinned and any(r.match(ms, old_dist.to_filename()) for ms in pinned_specs):

      File "/home/travis/miniconda/lib/python2.7/site-packages/conda/plan.py", line 776, in <genexpr>

        if pinned and any(r.match(ms, old_dist.to_filename()) for ms in pinned_specs):

      File "/home/travis/miniconda/lib/python2.7/site-packages/conda/resolve.py", line 474, in match

        rec = self.index[fkey]

    KeyError: u'astropy-1.0.3-np19py33_0.tar.bz2'
```

cc @astrofrog


Discussion:
Thanks for the report.  Digging in soon.
@kalefranz - I wonder why did you close this, is it already fixed in master?
I still see this Keyerror with version 4.3.5

https://travis-ci.org/bsipocz/package-template/jobs/193123449
I didn't know I did!!!!  It wasn't intentional.  Unless I thought it was fixed.  Looking again...

Resolving patch:
diff --git a/conda/plan.py b/conda/plan.py
--- a/conda/plan.py
+++ b/conda/plan.py
@@ -773,7 +773,7 @@ def remove_actions(prefix, specs, index, force=False, pinned=True):
         name = r.package_name(old_dist)
         if old_dist == nlinked.get(name):
             continue
-        if pinned and any(r.match(ms, old_dist.to_filename()) for ms in pinned_specs):
+        if pinned and any(r.match(ms, old_dist) for ms in pinned_specs):
             msg = "Cannot remove %s because it is pinned. Use --no-pin to override."
             raise CondaRuntimeError(msg % old_dist.to_filename())
         if context.conda_in_root and name == 'conda' and name not in nlinked and not context.force:


Test patch: