Repository: conda/conda

Issue:
Can no longer update, install, or remove
<!--
Hi!  Read this; it's important.

This is an issue tracker for conda -- the package manager.  File feature requests
for conda here, as well as bug reports about something conda has messed up.

If your issue is a bug report for:
  * a specific conda package from Anaconda ('defaults' channel):
      ==> file at https://github.com/ContinuumIO/anaconda-issues
  * a specific conda package from conda-forge:
      ==> file at the corresponding feedstock under https://github.com/conda-forge
  * repo.anaconda.com access and service:
      ==> file at https://github.com/ContinuumIO/anaconda-issues
  * anaconda.org access and service:
      ==> file at https://anaconda.org/contact/report
  * commands under 'conda build':
      ==> file at https://github.com/conda/conda-build
  * commands under 'conda env':
      ==> please file it here!
  * all other conda commands that start with 'conda':
      ==> please file it here!

If you continue on,

   **please include all requested information below.**

If a maintainer determines the information is required to understand 
your issue, and if it is not provided, your issue may be
closed automatically.

-->

## Current Behavior
<!-- What actually happens?
     If you want to include console output, please use "Steps to Reproduce" below. -->


### Steps to Reproduce
<!-- If the current behavior is a bug, please provide specific, minimal steps to independently reproduce.
     Include the exact conda commands that reproduce the issue and their output between the ticks below. -->
```
scopatz@artemis ~ $ conda remove conda-build                                        
Collecting package metadata (repodata.json): | WARNING conda.base.context:use_only_tar_bz2(632): Conda is constrained to only using the old .tar.bz2 file format because you have conda-build installed, and it is <3.18.3.  Update or remove conda-build to get smaller downloads and faster extractions.
done
Solving environment: failed

# >>>>>>>>>>>>>>>>>>>>>> ERROR REPORT <<<<<<<<<<<<<<<<<<<<<<

    Traceback (most recent call last):
      File "/home/scopatz/miniconda/lib/python3.7/site-packages/conda/resolve.py", line 453, in _get_strict_channel
        channel_name = self._strict_channel_cache[package_name]
    KeyError: 'mistune'
    
    During handling of the above exception, another exception occurred:
    
    Traceback (most recent call last):
      File "/home/scopatz/miniconda/lib/python3.7/site-packages/conda/exceptions.py", line 1043, in __call__
        return func(*args, **kwargs)
      File "/home/scopatz/miniconda/lib/python3.7/site-packages/conda/cli/main.py", line 84, in _main
        exit_code = do_call(args, p)
      File "/home/scopatz/miniconda/lib/python3.7/site-packages/conda/cli/conda_argparse.py", line 82, in do_call
        exit_code = getattr(module, func_name)(args, parser)
      File "/home/scopatz/miniconda/lib/python3.7/site-packages/conda/cli/main_remove.py", line 82, in execute
        txn = solver.solve_for_transaction()
      File "/home/scopatz/miniconda/lib/python3.7/site-packages/conda/core/solve.py", line 111, in solve_for_transaction
        force_remove, force_reinstall)
      File "/home/scopatz/miniconda/lib/python3.7/site-packages/conda/core/solve.py", line 149, in solve_for_diff
        force_remove)
      File "/home/scopatz/miniconda/lib/python3.7/site-packages/conda/core/solve.py", line 244, in solve_final_state
        ssc = self._add_specs(ssc)
      File "/home/scopatz/miniconda/lib/python3.7/site-packages/conda/core/solve.py", line 462, in _add_specs
        for _ in ssc.prefix_data.iter_records())))) or []
      File "/home/scopatz/miniconda/lib/python3.7/site-packages/conda/resolve.py", line 993, in get_conflicting_specs
        unsat_specs = {s for s in specs if not r2.find_matches_with_strict(s, scp)}
      File "/home/scopatz/miniconda/lib/python3.7/site-packages/conda/resolve.py", line 993, in <setcomp>
        unsat_specs = {s for s in specs if not r2.find_matches_with_strict(s, scp)}
      File "/home/scopatz/miniconda/lib/python3.7/site-packages/conda/resolve.py", line 327, in find_matches_with_strict
        sole_source_channel_name = self._get_strict_channel(ms.name)
      File "/home/scopatz/miniconda/lib/python3.7/site-packages/conda/resolve.py", line 455, in _get_strict_channel
        all_channel_names = set(prec.channel.name for prec in self.groups[package_name])
    KeyError: 'mistune'

`$ /home/scopatz/miniconda/bin/conda remove conda-build`

  environment variables:
                 CIO_TEST=<not set>
               CONDA_ROOT=/home/scopatz/miniconda
            DEFAULTS_PATH=/usr/share/gconf/awesome.default.path
           MANDATORY_PATH=/usr/share/gconf/awesome.mandatory.path
                     PATH=/home/scopatz/.local/bin:/home/scopatz/miniconda/bin:/usr/local/cuda-1
                          0.1/bin:/usr/local/cuda-10.1/NsightCompute-2019.1:/usr/local/sbin:/usr
                          /local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games:/
                          snap/bin
       REQUESTS_CA_BUNDLE=<not set>
            SSL_CERT_FILE=<not set>
               WINDOWPATH=2

     active environment : None
       user config file : /home/scopatz/.condarc
 populated config files : /home/scopatz/.condarc
          conda version : 4.7.2
    conda-build version : 3.18.2
         python version : 3.7.1.final.0
       virtual packages : 
       base environment : /home/scopatz/miniconda  (writable)
           channel URLs : https://conda.anaconda.org/conda-forge/linux-64
                          https://conda.anaconda.org/conda-forge/noarch
                          https://repo.anaconda.com/pkgs/main/linux-64
                          https://repo.anaconda.com/pkgs/main/noarch
                          https://repo.anaconda.com/pkgs/r/linux-64
                          https://repo.anaconda.com/pkgs/r/noarch
          package cache : /home/scopatz/miniconda/pkgs
                          /home/scopatz/.conda/pkgs
       envs directories : /home/scopatz/miniconda/envs
                          /home/scopatz/.conda/envs
               platform : linux-64
             user-agent : conda/4.7.2 requests/2.22.0 CPython/3.7.1 Linux/5.0.0-16-generic ubuntu/19.04 glibc/2.29
                UID:GID : 1000:1000
             netrc file : None
           offline mode : False


An unexpected error has occurred. Conda has prepared the above report.

Upload successful.
```


## Expected Behavior
<!-- What do you think should happen? -->

normal operation.

Let me know if you need anything else.



Discussion:

Resolving patch:
diff --git a/conda/resolve.py b/conda/resolve.py
--- a/conda/resolve.py
+++ b/conda/resolve.py
@@ -449,13 +449,15 @@ def find_conflicts(self, specs, specs_to_add=None, history_specs=None):
         raise UnsatisfiableError(bad_deps, strict=strict_channel_priority)
 
     def _get_strict_channel(self, package_name):
+        channel_name = None
         try:
             channel_name = self._strict_channel_cache[package_name]
         except KeyError:
-            all_channel_names = set(prec.channel.name for prec in self.groups[package_name])
-            by_cp = {self._channel_priorities_map.get(cn, 1): cn for cn in all_channel_names}
-            highest_priority = sorted(by_cp)[0]  # highest priority is the lowest number
-            channel_name = self._strict_channel_cache[package_name] = by_cp[highest_priority]
+            if package_name in self.groups:
+                all_channel_names = set(prec.channel.name for prec in self.groups[package_name])
+                by_cp = {self._channel_priorities_map.get(cn, 1): cn for cn in all_channel_names}
+                highest_priority = sorted(by_cp)[0]  # highest priority is the lowest number
+                channel_name = self._strict_channel_cache[package_name] = by_cp[highest_priority]
         return channel_name
 
     @memoizemethod


Test patch: