Repository: conda/conda

Issue:
Package is wrongly listed as from `pypi` channel / `conda list` crashes with a stacktrace
## Current Behavior

* `conda list` lists a package (`bleach`) as being from `pypi` instead of `conda-forge`
* sometimes `conda list` fails with a stacktrace


### Steps to Reproduce

```
 λ conda create -n test_bleach -c conda-forge bleach=3.1.0                                                               
Collecting package metadata: done                                                                                       
Solving environment: done                                                                                               
                                                                                                                        
## Package Plan ##                                                                                                      
                                                                                                                        
  environment location: W:\Miniconda3\envs\test_bleach                                                                  
                                                                                                                        
  added / updated specs:                                                                                                
    - bleach=3.1.0                                                                                                      
                                                                                                                        
                                                                                                                        
The following packages will be downloaded:                                                                              
                                                                                                                        
    package                    |            build                                                                       
    ---------------------------|-----------------                                                                       
    bleach-3.1.0               |             py_0         110 KB  conda-forge                                           
    certifi-2018.11.29         |        py37_1000         144 KB  conda-forge                                           
    pip-19.0.1                 |           py37_0         1.8 MB  conda-forge                                           
    python-3.7.1               |    hc182675_1000        20.9 MB  conda-forge                                           
    setuptools-40.7.1          |           py37_0         633 KB  conda-forge                                           
    six-1.12.0                 |        py37_1000          21 KB  conda-forge                                           
    vc-14                      |                0          985 B  conda-forge                                           
    vs2015_runtime-14.0.25420  |                0         1.9 MB  conda-forge                                           
    webencodings-0.5.1         |             py_1          12 KB  conda-forge                                           
    wheel-0.32.3               |           py37_0          51 KB  conda-forge                                           
    wincertstore-0.2           |        py37_1002          13 KB  conda-forge                                           
    ------------------------------------------------------------                                                        
                                           Total:        25.6 MB                                                        
                                                                                                                        
The following NEW packages will be INSTALLED:                                                                           
                                                                                                                        
  bleach             conda-forge/noarch::bleach-3.1.0-py_0                                                              
  certifi            conda-forge/win-64::certifi-2018.11.29-py37_1000                                                   
  pip                conda-forge/win-64::pip-19.0.1-py37_0                                                              
  python             conda-forge/win-64::python-3.7.1-hc182675_1000                                                     
  setuptools         conda-forge/win-64::setuptools-40.7.1-py37_0                                                       
  six                conda-forge/win-64::six-1.12.0-py37_1000                                                           
  vc                 conda-forge/win-64::vc-14-0                                                                        
  vs2015_runtime     conda-forge/win-64::vs2015_runtime-14.0.25420-0                                                    
  webencodings       conda-forge/noarch::webencodings-0.5.1-py_1                                                        
  wheel              conda-forge/win-64::wheel-0.32.3-py37_0                                                            
  wincertstore       conda-forge/win-64::wincertstore-0.2-py37_1002                                                     
                                                                                                                        
                                                                                                                        
Proceed ([y]/n)?                                                                                                        
                                                                                                                        
                                                                                                                        
Downloading and Extracting Packages                                                                                     
six-1.12.0           | 21 KB     | ############################################################################ | 100%  
vs2015_runtime-14.0. | 1.9 MB    | ############################################################################ | 100%  
wheel-0.32.3         | 51 KB     | ############################################################################ | 100%  
wincertstore-0.2     | 13 KB     | ############################################################################ | 100%  
certifi-2018.11.29   | 144 KB    | ############################################################################ | 100%  
setuptools-40.7.1    | 633 KB    | ############################################################################ | 100%  
webencodings-0.5.1   | 12 KB     | ############################################################################ | 100%  
python-3.7.1         | 20.9 MB   | ############################################################################ | 100%  
vc-14                | 985 B     | ############################################################################ | 100%  
bleach-3.1.0         | 110 KB    | ############################################################################ | 100%  
pip-19.0.1           | 1.8 MB    | ############################################################################ | 100%  
Preparing transaction: done                                                                                             
Verifying transaction: done                                                                                             
Executing transaction: \ WARNING conda.core.envs_manager:register_env(43): Unable to register environment. Path not writ
able.                                                                                                                   
  environment location: W:\Miniconda3\envs\test_bleach                                                                  
  registry file: C:\Users\tadeu\.conda\environments.txt                                                                 
done                                                                                                                    
#                                                                                                                       
# To activate this environment, use:                                                                                    
# > activate test_bleach                                                                                                
#                                                                                                                       
# To deactivate an active environment, use:                                                                             
# > deactivate                                                                                                          
#                                                                                                                       
# * for power-users using bash, you must source                                                                         
#                                                                                                                       

                                                                                                                        
λ conda list -n test_bleach                                                                                             
# packages in environment at W:\Miniconda3\envs\test_bleach:                                                            
#                                                                                                                       
# Name                    Version                   Build  Channel                                                      
certifi                   2018.11.29            py37_1000    conda-forge                                                
pip                       19.0.1                   py37_0    conda-forge                                                
python                    3.7.1             hc182675_1000    conda-forge                                                
setuptools                40.7.1                   py37_0    conda-forge                                                
six                       1.12.0                py37_1000    conda-forge                                                
vc                        14                            0    conda-forge                                                
vs2015_runtime            14.0.25420                    0    conda-forge                                                
webencodings              0.5.1                      py_1    conda-forge                                                
wheel                     0.32.3                   py37_0    conda-forge                                                
wincertstore              0.2                   py37_1002    conda-forge                                                
```
NOTE: doesn't even appear in the first listing, before `activate` ^

```
λ conda activate test_bleach                                                                                            
                                                                                                                        
(test_bleach) λ conda list                                                                                              
# packages in environment at W:\Miniconda3\envs\test_bleach:                                                            
#                                                                                                                       
# Name                    Version                   Build  Channel                                                      
bleach                    3.1.0                    pypi_0    pypi                                                       
certifi                   2018.11.29            py37_1000    conda-forge                                                
pip                       19.0.1                   py37_0    conda-forge                                                
python                    3.7.1             hc182675_1000    conda-forge                                                
setuptools                40.7.1                   py37_0    conda-forge                                                
six                       1.12.0                py37_1000    conda-forge                                                
vc                        14                            0    conda-forge                                                
vs2015_runtime            14.0.25420                    0    conda-forge                                                
webencodings              0.5.1                      py_1    conda-forge                                                
wheel                     0.32.3                   py37_0    conda-forge                                                
wincertstore              0.2                   py37_1002    conda-forge                                                
```

Note that `bleach` is listed as if coming from pip/`pypi`!

Sometimes there is a more serious error on `conda list` (seems to be very related, but I couldn't get an easy way to reproduce it yet), it will print this stacktrace:

```
    Traceback (most recent call last):
      File "W:\Miniconda\lib\site-packages\conda\exceptions.py", line 1001, in __call__
        return func(*args, **kwargs)
      File "W:\Miniconda\lib\site-packages\conda\cli\main.py", line 84, in _main
        exit_code = do_call(args, p)
      File "W:\Miniconda\lib\site-packages\conda\cli\conda_argparse.py", line 81, in do_call
        exit_code = getattr(module, func_name)(args, parser)
      File "W:\Miniconda\lib\site-packages\conda\cli\main_list.py", line 142, in execute
        show_channel_urls=context.show_channel_urls)
      File "W:\Miniconda\lib\site-packages\conda\cli\main_list.py", line 80, in print_packages
        show_channel_urls=show_channel_urls)
      File "W:\Miniconda\lib\site-packages\conda\cli\main_list.py", line 45, in list_packages
        installed = sorted(PrefixData(prefix, pip_interop_enabled=True).iter_records(),
      File "W:\Miniconda\lib\site-packages\conda\core\prefix_data.py", line 116, in iter_records
        return itervalues(self._prefix_records)
      File "W:\Miniconda\lib\site-packages\conda\core\prefix_data.py", line 145, in _prefix_records
        return self.__prefix_records or self.load() or self.__prefix_records
      File "W:\Miniconda\lib\site-packages\conda\core\prefix_data.py", line 69, in load
        self._load_site_packages()
      File "W:\Miniconda\lib\site-packages\conda\core\prefix_data.py", line 237, in _load_site_packages
        prefix_rec = self._prefix_records.pop(conda_python_packages[conda_anchor_file].name)
    KeyError: 'bleach'
```


## Expected Behavior

The package should be listed with the proper channel and there should be no error with stacktrace in `conda list`.


## Environment Information
<details open><summary><code>`conda info`</code></summary><p>
<!-- between the ticks below, paste the output of 'conda info' -->

```
     active environment : None
            shell level : 0
       user config file : C:\Users\tadeu\.condarc
 populated config files :
          conda version : 4.6.1
    conda-build version : not installed
         python version : 3.7.1.final.0
       base environment : W:\Miniconda3  (writable)
           channel URLs : https://repo.anaconda.com/pkgs/main/win-64
                          https://repo.anaconda.com/pkgs/main/noarch
                          https://repo.anaconda.com/pkgs/free/win-64
                          https://repo.anaconda.com/pkgs/free/noarch
                          https://repo.anaconda.com/pkgs/r/win-64
                          https://repo.anaconda.com/pkgs/r/noarch
                          https://repo.anaconda.com/pkgs/msys2/win-64
                          https://repo.anaconda.com/pkgs/msys2/noarch
          package cache : W:\Miniconda3\pkgs
                          C:\Users\tadeu\.conda\pkgs
                          C:\Users\tadeu\AppData\Local\conda\conda\pkgs
       envs directories : W:\Miniconda3\envs
                          C:\Users\tadeu\.conda\envs
                          C:\Users\tadeu\AppData\Local\conda\conda\envs
               platform : win-64
             user-agent : conda/4.6.1 requests/2.21.0 CPython/3.7.1 Windows/10 Windows/10.0.17134
          administrator : True
             netrc file : None
           offline mode : False
```
</p></details>


<details open><summary><code>`conda config --show-sources`</code></summary><p>
<!-- between the ticks below, paste the output of 'conda config --show-sources' -->

```

```
</p></details>


<details><summary><code>`conda list --show-channel-urls`</code></summary><p>
<!-- between the ticks below, paste the output of 'conda list --show-channel-urls' -->

```
# packages in environment at W:\Miniconda3:
#
# Name                    Version                   Build  Channel
asn1crypto                0.24.0                   py37_0    defaults
ca-certificates           2018.12.5                     0    defaults
certifi                   2018.11.29               py37_0    defaults
cffi                      1.11.5           py37h74b6da3_1    defaults
chardet                   3.0.4                    py37_1    defaults
conda                     4.6.1                    py37_0    defaults
conda-env                 2.6.0                         1    defaults
console_shortcut          0.1.1                         3    defaults
cryptography              2.4.2            py37h7a1dbc1_0    defaults
idna                      2.8                      py37_0    defaults
menuinst                  1.4.14           py37hfa6e2cd_0    defaults
openssl                   1.1.1a               he774522_0    defaults
pip                       18.1                     py37_0    defaults
pycosat                   0.6.3            py37hfa6e2cd_0    defaults
pycparser                 2.19                     py37_0    defaults
pyopenssl                 18.0.0                   py37_0    defaults
pysocks                   1.6.8                    py37_0    defaults
python                    3.7.1                h8c8aaf0_6    defaults
pywin32                   223              py37hfa6e2cd_1    defaults
requests                  2.21.0                   py37_0    defaults
ruamel_yaml               0.15.46          py37hfa6e2cd_0    defaults
setuptools                40.6.3                   py37_0    defaults
six                       1.12.0                   py37_0    defaults
sqlite                    3.26.0               he774522_0    defaults
urllib3                   1.24.1                   py37_0    defaults
vc                        14.1                 h0510ff6_4    defaults
vs2015_runtime            14.15.26706          h3a45250_0    defaults
wheel                     0.32.3                   py37_0    defaults
win_inet_pton             1.0.1                    py37_1    defaults
wincertstore              0.2                      py37_0    defaults
yaml                      0.1.7                hc54c509_2    defaults
```
</p></details>



Discussion:
Note that this is reproducible without `conda-forge`:

```
λ conda create -n test_bleach_2 bleach                                                                                  
Collecting package metadata: done                                                                                       
Solving environment: done                                                                                               
                                                                                                                        
## Package Plan ##                                                                                                      
                                                                                                                        
  environment location: W:\Miniconda3\envs\test_bleach_2                                                                
                                                                                                                        
  added / updated specs:                                                                                                
    - bleach                                                                                                            
                                                                                                                        
                                                                                                                        
The following packages will be downloaded:                                                                              
                                                                                                                        
    package                    |            build                                                                       
    ---------------------------|-----------------                                                                       
    bleach-3.1.0               |           py37_0         222 KB                                                        
    python-3.7.2               |       h8c8aaf0_0        17.7 MB                                                        
    webencodings-0.5.1         |           py37_1          19 KB                                                        
    wheel-0.32.3               |           py37_0          53 KB                                                        
    ------------------------------------------------------------                                                        
                                           Total:        18.0 MB                                                        
                                                                                                                        
The following NEW packages will be INSTALLED:                                                                           
                                                                                                                        
  bleach             pkgs/main/win-64::bleach-3.1.0-py37_0                                                              
  ca-certificates    pkgs/main/win-64::ca-certificates-2018.12.5-0                                                      
  certifi            pkgs/main/win-64::certifi-2018.11.29-py37_0                                                        
  openssl            pkgs/main/win-64::openssl-1.1.1a-he774522_0                                                        
  pip                pkgs/main/win-64::pip-18.1-py37_0                                                                  
  python             pkgs/main/win-64::python-3.7.2-h8c8aaf0_0                                                          
  setuptools         pkgs/main/win-64::setuptools-40.6.3-py37_0                                                         
  six                pkgs/main/win-64::six-1.12.0-py37_0                                                                
  sqlite             pkgs/main/win-64::sqlite-3.26.0-he774522_0                                                         
  vc                 pkgs/main/win-64::vc-14.1-h0510ff6_4                                                               
  vs2015_runtime     pkgs/main/win-64::vs2015_runtime-14.15.26706-h3a45250_0                                            
  webencodings       pkgs/main/win-64::webencodings-0.5.1-py37_1                                                        
  wheel              pkgs/main/win-64::wheel-0.32.3-py37_0                                                              
  wincertstore       pkgs/main/win-64::wincertstore-0.2-py37_0                                                          
                                                                                                                        
                                                                                                                        
Proceed ([y]/n)?                                                                                                        
                                                                                                                        
                                                                                                                        
Downloading and Extracting Packages                                                                                     
wheel-0.32.3         | 53 KB     | ############################################################################ | 100%  
webencodings-0.5.1   | 19 KB     | ############################################################################ | 100%  
bleach-3.1.0         | 222 KB    | ############################################################################ | 100%  
python-3.7.2         | 17.7 MB   | ############################################################################ | 100%  
Preparing transaction: done                                                                                             
Verifying transaction: done                                                                                             
Executing transaction: / WARNING conda.core.envs_manager:register_env(43): Unable to register environment. Path not writ
able.                                                                                                                   
  environment location: W:\Miniconda3\envs\test_bleach_2                                                                
  registry file: C:\Users\tadeu\.conda\environments.txt                                                                 
done                                                                                                                    
#                                                                                                                       
# To activate this environment, use                                                                                     
#                                                                                                                       
#     $ conda activate test_bleach_2                                                                                    
#                                                                                                                       
# To deactivate an active environment, use                                                                              
#                                                                                                                       
#     $ conda deactivate                                                                                                
                                                                                                                        
                                                                                                                        
λ conda list -n test_bleach_2                                                                                           
# packages in environment at W:\Miniconda3\envs\test_bleach_2:                                                          
#                                                                                                                       
# Name                    Version                   Build  Channel                                                      
ca-certificates           2018.12.5                     0                                                               
certifi                   2018.11.29               py37_0                                                               
openssl                   1.1.1a               he774522_0                                                               
pip                       18.1                     py37_0                                                               
python                    3.7.2                h8c8aaf0_0                                                               
setuptools                40.6.3                   py37_0                                                               
six                       1.12.0                   py37_0                                                               
sqlite                    3.26.0               he774522_0                                                               
vc                        14.1                 h0510ff6_4                                                               
vs2015_runtime            14.15.26706          h3a45250_0                                                               
webencodings              0.5.1                    py37_1                                                               
wheel                     0.32.3                   py37_0                                                               
wincertstore              0.2                      py37_0                                                               

                                                                                                                        
λ activate test_bleach_2                                                                                                
                                                                                                                        
conda.bat activate test_bleach_2                                                                                        
                                                                                                                        
(test_bleach_2) λ conda list                                                                                            
# packages in environment at W:\Miniconda3\envs\test_bleach_2:                                                          
#                                                                                                                       
# Name                    Version                   Build  Channel                                                      
bleach                    3.1.0                    pypi_0    pypi                                                       
ca-certificates           2018.12.5                     0                                                               
certifi                   2018.11.29               py37_0                                                               
openssl                   1.1.1a               he774522_0                                                               
pip                       18.1                     py37_0                                                               
python                    3.7.2                h8c8aaf0_0                                                               
setuptools                40.6.3                   py37_0                                                               
six                       1.12.0                   py37_0                                                               
sqlite                    3.26.0               he774522_0                                                               
vc                        14.1                 h0510ff6_4                                                               
vs2015_runtime            14.15.26706          h3a45250_0                                                               
webencodings              0.5.1                    py37_1                                                               
wheel                     0.32.3                   py37_0                                                               
wincertstore              0.2                      py37_0                                                               
```
I've noticed that there's something weird in the `conda-meta/history` file:

```
==> 2019-01-30 13:57:26 <==
# cmd: W:\Miniconda3\Scripts\conda-script.py create -n test_bleach_2 bleach
# conda version: 4.6.1
+defaults::bleach-3.1.0-py37_0
+defaults::ca-certificates-2018.12.5-0
+defaults::certifi-2018.11.29-py37_0
+defaults::openssl-1.1.1a-he774522_0
+defaults::pip-18.1-py37_0
+defaults::python-3.7.2-h8c8aaf0_0
+defaults::setuptools-40.6.3-py37_0
+defaults::six-1.12.0-py37_0
+defaults::sqlite-3.26.0-he774522_0
+defaults::vc-14.1-h0510ff6_4
+defaults::vs2015_runtime-14.15.26706-h3a45250_0
+defaults::webencodings-0.5.1-py37_1
+defaults::wheel-0.32.3-py37_0
+defaults::wincertstore-0.2-py37_0
# update specs: ['bleach']
```

`bleach` is installed from `defaults`, but in the end there is this `"update specs: ['bleach']"`
I saw this in the uploaded error reports.  Several times, but only with the `bleach` package.  Seems like there's something peculiar going on with https://conda.anaconda.org/conda-forge/noarch/bleach-3.1.0-py_0.tar.bz2?
What type of json files associated with `bleach` do you see in the `conda-meta/` directory?
There's no json for `bleach` in `conda-meta/`, right after the env creation:

```
certifi-2018.11.29-py37_1000.json
history
pip-19.0.1-py37_0.json
python-3.7.1-hc182675_1000.json
setuptools-40.7.1-py37_0.json
six-1.12.0-py37_1000.json
vc-14-0.json
vs2015_runtime-14.0.25420-0.json
webencodings-0.5.1-py_1.json
wheel-0.32.3-py37_0.json
wincertstore-0.2-py37_1002.json
```

I've reproduced exactly the same behavior on macOS instead of Windows.

```
$ conda create -n test_bleach_2 -c conda-forge bleach
Collecting package metadata: done
Solving environment: done

## Package Plan ##

  environment location: /Users/kfranz/continuum/conda/devenv/envs/test_bleach_2

  added / updated specs:
    - bleach


The following packages will be downloaded:

    package                    |            build
    ---------------------------|-----------------
    bleach-3.1.0               |             py_0         110 KB  conda-forge
    bzip2-1.0.6                |    h1de35cc_1002         148 KB  conda-forge
    ca-certificates-2018.11.29 |       ha4d7672_0         143 KB  conda-forge
    certifi-2018.11.29         |        py37_1000         145 KB  conda-forge
    libcxx-7.0.0               |       h2d50403_2         1.1 MB  conda-forge
    libffi-3.2.1               |    h0a44026_1005          42 KB  conda-forge
    llvm-meta-7.0.0            |                0           2 KB  conda-forge
    ncurses-6.1                |    h0a44026_1002         1.3 MB  conda-forge
    openssl-1.0.2p             |    h1de35cc_1002         3.0 MB  conda-forge
    pip-19.0.1                 |           py37_0         1.8 MB  conda-forge
    python-3.7.1               |    h145921a_1000        21.8 MB  conda-forge
    readline-7.0               |    hcfe32e1_1001         393 KB  conda-forge
    setuptools-40.7.1          |           py37_0         632 KB  conda-forge
    six-1.12.0                 |        py37_1000          22 KB  conda-forge
    sqlite-3.26.0              |    h1765d9f_1000         2.4 MB  conda-forge
    tk-8.6.9                   |    ha441bb4_1000         3.1 MB  conda-forge
    webencodings-0.5.1         |             py_1          12 KB  conda-forge
    wheel-0.32.3               |           py37_0          34 KB  conda-forge
    xz-5.2.4                   |    h1de35cc_1001         268 KB  conda-forge
    zlib-1.2.11                |    h1de35cc_1004         101 KB  conda-forge
    ------------------------------------------------------------
                                           Total:        36.6 MB

The following NEW packages will be INSTALLED:

  bleach             conda-forge/noarch::bleach-3.1.0-py_0
  bzip2              conda-forge/osx-64::bzip2-1.0.6-h1de35cc_1002
  ca-certificates    conda-forge/osx-64::ca-certificates-2018.11.29-ha4d7672_0
  certifi            conda-forge/osx-64::certifi-2018.11.29-py37_1000
  libcxx             conda-forge/osx-64::libcxx-7.0.0-h2d50403_2
  libffi             conda-forge/osx-64::libffi-3.2.1-h0a44026_1005
  llvm-meta          conda-forge/noarch::llvm-meta-7.0.0-0
  ncurses            conda-forge/osx-64::ncurses-6.1-h0a44026_1002
  openssl            conda-forge/osx-64::openssl-1.0.2p-h1de35cc_1002
  pip                conda-forge/osx-64::pip-19.0.1-py37_0
  python             conda-forge/osx-64::python-3.7.1-h145921a_1000
  readline           conda-forge/osx-64::readline-7.0-hcfe32e1_1001
  setuptools         conda-forge/osx-64::setuptools-40.7.1-py37_0
  six                conda-forge/osx-64::six-1.12.0-py37_1000
  sqlite             conda-forge/osx-64::sqlite-3.26.0-h1765d9f_1000
  tk                 conda-forge/osx-64::tk-8.6.9-ha441bb4_1000
  webencodings       conda-forge/noarch::webencodings-0.5.1-py_1
  wheel              conda-forge/osx-64::wheel-0.32.3-py37_0
  xz                 conda-forge/osx-64::xz-5.2.4-h1de35cc_1001
  zlib               conda-forge/osx-64::zlib-1.2.11-h1de35cc_1004


Proceed ([y]/n)? y


Downloading and Extracting Packages
libcxx-7.0.0         | 1.1 MB    | ###################################################################################################################################################### | 100%
certifi-2018.11.29   | 145 KB    | ###################################################################################################################################################### | 100%
bleach-3.1.0         | 110 KB    | ###################################################################################################################################################### | 100%
setuptools-40.7.1    | 632 KB    | ###################################################################################################################################################### | 100%
openssl-1.0.2p       | 3.0 MB    | ###################################################################################################################################################### | 100%
xz-5.2.4             | 268 KB    | ###################################################################################################################################################### | 100%
pip-19.0.1           | 1.8 MB    | ###################################################################################################################################################### | 100%
bzip2-1.0.6          | 148 KB    | ###################################################################################################################################################### | 100%
six-1.12.0           | 22 KB     | ###################################################################################################################################################### | 100%
libffi-3.2.1         | 42 KB     | ###################################################################################################################################################### | 100%
python-3.7.1         | 21.8 MB   | ###################################################################################################################################################### | 100%
ca-certificates-2018 | 143 KB    | ###################################################################################################################################################### | 100%
ncurses-6.1          | 1.3 MB    | ###################################################################################################################################################### | 100%
sqlite-3.26.0        | 2.4 MB    | ###################################################################################################################################################### | 100%
zlib-1.2.11          | 101 KB    | ###################################################################################################################################################### | 100%
wheel-0.32.3         | 34 KB     | ###################################################################################################################################################### | 100%
readline-7.0         | 393 KB    | ###################################################################################################################################################### | 100%
llvm-meta-7.0.0      | 2 KB      | ###################################################################################################################################################### | 100%
tk-8.6.9             | 3.1 MB    | ###################################################################################################################################################### | 100%
webencodings-0.5.1   | 12 KB     | ###################################################################################################################################################### | 100%
Preparing transaction: done
Verifying transaction: done
Executing transaction: done
#
# To activate this environment, use
#
#     $ conda activate test_bleach_2
#
# To deactivate an active environment, use
#
#     $ conda deactivate

$ conda list -n test_bleach_2
# packages in environment at /Users/kfranz/continuum/conda/devenv/envs/test_bleach_2:
#
# Name                    Version                   Build  Channel
bzip2                     1.0.6             h1de35cc_1002    conda-forge
ca-certificates           2018.11.29           ha4d7672_0    conda-forge
certifi                   2018.11.29            py37_1000    conda-forge
libcxx                    7.0.0                h2d50403_2    conda-forge
libffi                    3.2.1             h0a44026_1005    conda-forge
llvm-meta                 7.0.0                         0    conda-forge
ncurses                   6.1               h0a44026_1002    conda-forge
openssl                   1.0.2p            h1de35cc_1002    conda-forge
pip                       19.0.1                   py37_0    conda-forge
python                    3.7.1             h145921a_1000    conda-forge
readline                  7.0               hcfe32e1_1001    conda-forge
setuptools                40.7.1                   py37_0    conda-forge
six                       1.12.0                py37_1000    conda-forge
sqlite                    3.26.0            h1765d9f_1000    conda-forge
tk                        8.6.9             ha441bb4_1000    conda-forge
webencodings              0.5.1                      py_1    conda-forge
wheel                     0.32.3                   py37_0    conda-forge
xz                        5.2.4             h1de35cc_1001    conda-forge
zlib                      1.2.11            h1de35cc_1004    conda-forge
$ conda activate test_bleach_2
$ conda list
# packages in environment at /Users/kfranz/continuum/conda/devenv/envs/test_bleach_2:
#
# Name                    Version                   Build  Channel
bleach                    3.1.0                    pypi_0    pypi
bzip2                     1.0.6             h1de35cc_1002    conda-forge
ca-certificates           2018.11.29           ha4d7672_0    conda-forge
certifi                   2018.11.29            py37_1000    conda-forge
libcxx                    7.0.0                h2d50403_2    conda-forge
libffi                    3.2.1             h0a44026_1005    conda-forge
llvm-meta                 7.0.0                         0    conda-forge
ncurses                   6.1               h0a44026_1002    conda-forge
openssl                   1.0.2p            h1de35cc_1002    conda-forge
pip                       19.0.1                   py37_0    conda-forge
python                    3.7.1             h145921a_1000    conda-forge
readline                  7.0               hcfe32e1_1001    conda-forge
setuptools                40.7.1                   py37_0    conda-forge
six                       1.12.0                py37_1000    conda-forge
sqlite                    3.26.0            h1765d9f_1000    conda-forge
tk                        8.6.9             ha441bb4_1000    conda-forge
webencodings              0.5.1                      py_1    conda-forge
wheel                     0.32.3                   py37_0    conda-forge
xz                        5.2.4             h1de35cc_1001    conda-forge
zlib                      1.2.11            h1de35cc_1004    conda-forge
```
Ok the bit of logic in play here is at

https://github.com/conda/conda/blob/7a68286a737c7b5cd48c83d39bd615f99d939304/conda/core/prefix_data.py#L232-L252

The problem is that we're actually deleting the `bleach` record in `conda-meta`.

The value of `clobbered_conda_anchor_files` is `{'lib/python3.7/site-packages/bleach/_vendor/html5lib-1.0.1.dist-info/RECORD'}`.

The value of `conda_anchor_files` is `{'lib/python3.7/site-packages/bleach/_vendor/html5lib-1.0.1.dist-info/RECORD', 'lib/python3.7/site-packages/setuptools-40.7.1-py3.7.egg-info/PKG-INFO', 'lib/python3.7/site-packages/six-1.12.0-py3.7.egg-info/PKG-INFO', 'lib/python3.7/site-packages/webencodings-0.5.1-py2.7.egg-info/PKG-INFO', 'lib/python3.7/site-packages/bleach-3.1.0.dist-info/RECORD', 'lib/python3.7/site-packages/pip-19.0.1-py3.7.egg-info/PKG-INFO', 'lib/python3.7/site-packages/wheel-0.32.3-py3.7.egg-info/PKG-INFO', 'lib/python3.7/site-packages/certifi-2018.11.29-py3.7.egg-info'}`, which has two entries for the bleach package.

So the root cause is in

https://github.com/conda/conda/blob/7a68286a737c7b5cd48c83d39bd615f99d939304/conda/core/prefix_data.py#L280-L291

Alternately, maybe we should consider that bleach package malformed?

Resolving patch:
diff --git a/conda/core/prefix_data.py b/conda/core/prefix_data.py
--- a/conda/core/prefix_data.py
+++ b/conda/core/prefix_data.py
@@ -7,6 +7,7 @@
 from logging import getLogger
 from os import listdir
 from os.path import basename, isdir, isfile, join, lexists
+import re
 
 from .._vendor.auxlib.exceptions import ValidationError
 from ..base.constants import CONDA_TARBALL_EXTENSION, PREFIX_MAGIC_FILE
@@ -220,7 +221,9 @@ def _load_site_packages(self):
         # Get anchor files for corresponding conda (handled) python packages
         prefix_graph = PrefixGraph(self.iter_records())
         python_records = prefix_graph.all_descendants(python_pkg_record)
-        conda_python_packages = get_conda_anchor_files_and_records(python_records)
+        conda_python_packages = get_conda_anchor_files_and_records(
+            site_packages_dir, python_records
+        )
 
         # Get all anchor files and compare against conda anchor files to find clobbered conda
         # packages and python packages installed via other means (not handled by conda)
@@ -276,16 +279,27 @@ def _load_site_packages(self):
         return new_packages
 
 
-def get_conda_anchor_files_and_records(python_records):
+def get_conda_anchor_files_and_records(site_packages_short_path, python_records):
     """Return the anchor files for the conda records of python packages."""
     anchor_file_endings = ('.egg-info/PKG-INFO', '.dist-info/RECORD', '.egg-info')
     conda_python_packages = odict()
 
+    matcher = re.compile(
+        r"^%s/[^/]+(?:%s)$" % (
+            re.escape(site_packages_short_path),
+            r"|".join(re.escape(fn) for fn in anchor_file_endings)
+        )
+    ).match
+
     for prefix_record in python_records:
-        for fpath in prefix_record.files:
-            if fpath.endswith(anchor_file_endings) and 'site-packages' in fpath:
-                # Then 'fpath' is an anchor file
-                conda_python_packages[fpath] = prefix_record
+        anchor_paths = tuple(fpath for fpath in prefix_record.files if matcher(fpath))
+        if len(anchor_paths) > 1:
+            anchor_path = sorted(anchor_paths, key=len)[0]
+            log.info("Package %s has multiple python anchor files.\n"
+                     "  Using %s", prefix_record.record_id(), anchor_path)
+            conda_python_packages[anchor_path] = prefix_record
+        elif anchor_paths:
+            conda_python_packages[anchor_paths[0]] = prefix_record
 
     return conda_python_packages
 


Test patch:
diff --git a/tests/core/test_prefix_data.py b/tests/core/test_prefix_data.py
--- a/tests/core/test_prefix_data.py
+++ b/tests/core/test_prefix_data.py
@@ -136,18 +136,19 @@ def test_pip_interop_osx():
 
 def test_get_conda_anchor_files_and_records():
     valid_tests = [
-        os.sep.join(('v', 'site-packages', 'spam', '.egg-info', 'PKG-INFO')),
-        os.sep.join(('v', 'site-packages', 'foo', '.dist-info', 'RECORD')),
-        os.sep.join(('v', 'site-packages', 'bar', '.egg-info')),
+        'v/site-packages/spam.egg-info/PKG-INFO',
+        'v/site-packages/foo.dist-info/RECORD',
+        'v/site-packages/bar.egg-info',
     ]
     invalid_tests = [
-        os.sep.join(('i', 'site-packages', '.egg-link')),
-        os.sep.join(('i', 'spam', '.egg-info', 'PKG-INFO')),
-        os.sep.join(('i', 'foo', '.dist-info', 'RECORD')),
-        os.sep.join(('i', 'bar', '.egg-info')),
-        os.sep.join(('i', 'site-packages', 'spam')),
-        os.sep.join(('i', 'site-packages', 'foo')),
-        os.sep.join(('i', 'site-packages', 'bar')),
+        'v/site-packages/valid-package/_vendor/invalid-now.egg-info/PKG-INFO',
+        'i/site-packages/stuff.egg-link',
+        'i/spam.egg-info/PKG-INFO',
+        'i/foo.dist-info/RECORD',
+        'i/bar.egg-info',
+        'i/site-packages/spam',
+        'i/site-packages/foo',
+        'i/site-packages/bar',
     ]
     tests = valid_tests + invalid_tests
     records = []
@@ -156,10 +157,10 @@ def test_get_conda_anchor_files_and_records():
         record.files = [path]
         records.append(record)
 
-    output = get_conda_anchor_files_and_records(records)
+    output = get_conda_anchor_files_and_records("v/site-packages", records)
     expected_output = odict()
     for i in range(len(valid_tests)):
         expected_output[valid_tests[i]] = records[i]
 
     _print_output(output, expected_output)
-    assert output, expected_output
+    assert output == expected_output