Repository: conda/conda

Issue:
Conda checks for newer versions in channels in current context instead of only base channels
<!--
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 or feature request 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, and especially if you are submitting a bug report,

   **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.

-->

**I'm submitting a...**
  - [x] bug report
  - [ ] feature request


## Current Behavior
<!-- What actually happens?
     If you want to include console output, please use "Steps to Reproduce" below. -->
My base environment uses only the default channels. When I attempted to create a new environment using the conda-forge channel, conda found a newer conda version in conda-forge and warned about it. However, there is no newer version in the default channels to install.


### 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. -->
```
(base) λ conda create --name test --channel conda-forge --dry-run
Solving environment: done


==> WARNING: A newer version of conda exists. <==
  current version: 4.5.0
  latest version: 4.5.1

Please update conda by running

    $ conda update -n base conda



## Package Plan ##

  environment location: C:\Users\stan.west\Programs\Miniconda3-64\envs\test


(base) λ conda update conda
Solving environment: done

# All requested packages already installed.
```

At the moment, conda-forge has conda-4.5.1, but the default channels have only conda-4.5.0:
```
(base) λ conda search --channel conda-forge "conda>=4.5"
Loading channels: done
# Name                  Version           Build  Channel
conda                     4.5.0          py27_0  conda-forge
conda                     4.5.0          py27_0  pkgs/main
conda                     4.5.0          py35_0  conda-forge
conda                     4.5.0          py35_0  pkgs/main
conda                     4.5.0          py36_0  conda-forge
conda                     4.5.0          py36_0  pkgs/main
conda                     4.5.1          py27_0  conda-forge
conda                     4.5.1          py35_0  conda-forge
conda                     4.5.1          py36_0  conda-forge
```


## Expected Behavior
<!-- What do you think should happen? -->
Conda seeks newer versions only in channels used in the base environment and ignores newer versions in other channels.


## Environment Information
<details open><summary><code>`conda info`</code></summary><p>
<!-- between the ticks below, paste the output of 'conda info' -->

```
     active environment : base
    active env location : C:\Users\stan.west\Programs\Miniconda3-64
            shell level : 1
       user config file : C:\Users\stan.west\.condarc
 populated config files :
          conda version : 4.5.0
    conda-build version : not installed
         python version : 3.6.5.final.0
       base environment : C:\Users\stan.west\Programs\Miniconda3-64  (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/pro/win-64
                          https://repo.anaconda.com/pkgs/pro/noarch
                          https://repo.anaconda.com/pkgs/msys2/win-64
                          https://repo.anaconda.com/pkgs/msys2/noarch
          package cache : C:\Users\stan.west\Programs\Miniconda3-64\pkgs
                          C:\Users\stan.west\AppData\Local\conda\conda\pkgs
       envs directories : C:\Users\stan.west\Programs\Miniconda3-64\envs
                          C:\Users\stan.west\AppData\Local\conda\conda\envs
                          C:\Users\stan.west\.conda\envs
               platform : win-64
             user-agent : conda/4.5.0 requests/2.18.4 CPython/3.6.5 Windows/10 Windows/10.0.16299
          administrator : False
             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' -->

(There is no output.)
</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 C:\Users\stan.west\Programs\Miniconda3-64:
#
# Name                    Version                   Build  Channel
asn1crypto                0.24.0                   py36_0    defaults
ca-certificates           2018.03.07                    0    defaults
certifi                   2018.1.18                py36_0    defaults
cffi                      1.11.5           py36h945400d_0    defaults
chardet                   3.0.4            py36h420ce6e_1    defaults
conda                     4.5.0                    py36_0    defaults
conda-env                 2.6.0                h36134e3_1    defaults
console_shortcut          0.1.1                h6bb2dd7_3    defaults
cryptography              2.2.2            py36hfa6e2cd_0    defaults
idna                      2.6              py36h148d497_1    defaults
menuinst                  1.4.11           py36hfa6e2cd_0    defaults
openssl                   1.0.2o               h8ea7d77_0    defaults
pip                       9.0.3                    py36_0    defaults
pycosat                   0.6.3            py36h413d8a4_0    defaults
pycparser                 2.18             py36hd053e01_1    defaults
pyopenssl                 17.5.0           py36h5b7d817_0    defaults
pysocks                   1.6.8                    py36_0    defaults
python                    3.6.5                h0c2934d_0    defaults
pywin32                   223              py36hfa6e2cd_0    defaults
requests                  2.18.4           py36h4371aae_1    defaults
ruamel_yaml               0.15.35          py36hfa6e2cd_1    defaults
setuptools                39.0.1                   py36_0    defaults
six                       1.11.0           py36h4db2310_1    defaults
urllib3                   1.22             py36h276f60a_0    defaults
vc                        14                   h0510ff6_3    defaults
vs2015_runtime            14.0.25123                    3    defaults
wheel                     0.31.0                   py36_0    defaults
win_inet_pton             1.0.1            py36he67d7fd_1    defaults
wincertstore              0.2              py36h7fe50ca_0    defaults
yaml                      0.1.7                hc54c509_2    defaults
```
</p></details>



Discussion:
I don't see why you consider this a bug, can you explain?
I see it as a bug for a few reasons:

  * I found the situation puzzling. Conda instructed me to update conda with `conda update -n base conda`, but that command indicated that conda was current. Also, my initial search for conda packages (before I included the conda-forge channel) found no updates:

        (base) λ conda search "conda>=4.5"
        Loading channels: done
        # Name                  Version           Build  Channel
        conda                     4.5.0          py27_0  pkgs/main
        conda                     4.5.0          py35_0  pkgs/main
        conda                     4.5.0          py36_0  pkgs/main

  * If one doesn't intend to add the extra channel to the base environment, the warning is just noise. One could ignore the noise, but see also the next reason.

  * If the base environment's channels later acquire the newer conda version, I imagine that the warning wouldn't change to indicate that conda can be updated with the base environment's current channels.
I was confused by this as well.

```
$ conda update -n base conda
Solving environment: done


==> WARNING: A newer version of conda exists. <==
  current version: 4.5.0
  latest version: 4.5.1

Please update conda by running

    $ conda update -n base conda



# All requested packages already installed.
```

I use conda-forge but I pinned conda to the defaults channel:
```
$ cat /opt/conda/.condarc
pinned_packages:
  - defaults::conda
channels:
  - conda-forge
  - defaults
auto_update_conda: false
show_channel_urls: true
```

I'd expect the warning to be raised only when a new version is available in the pinned package channel.
Definitely something that needs to be fixed.
duplicate report: https://github.com/conda/conda/issues/7236
I'm having a similar issue. Right now ``conda update --all`` is running exceptionally slow (as after an hour it still will not complete). My only channels are defaults and conda-forge, but recently I installed a number of packages directly from the r channel. I recall reading that updating through the r channel takes a very long time, if it updates at all. After reading this bug I'm wondering if conda update is running slow because it's checking r, despite it not being on my channel list. Could that be the case?

If so--how would I resolve this? Would I need to uninstall all the packages currently associated with r and then reinstall them from a different channel?
You don't need to update or add an r channel, it's part of defaults.

It's not known to be slow to update things from that channel either. If you pass `-c r` explicitly then that will be slower than using the default channel location (https://repo.continuum.io/pkgs/r) due to differences in how they are served.
Ah, for some reason I thought r was not part of defaults. In that case I have no idea why ``conda update --all`` has decided to run so slowly, because as I said, I am not updating directly from the r channel. I may need to create a new issue.
@MattJEM not sure if you've figured out why it's updating so slowly, but in my experience using R packages that are in both the R channel and conda-forge causes environment solving to slow greatly or even fail. I ended up having to remove the R channel from defaults and install all my R packages from conda-forge.
R on `defaults` is a *lot* faster than R on `conda-forge` (this is true both MRO and non-MRO variants).

Resolving patch:
diff --git a/conda/core/solve.py b/conda/core/solve.py
--- a/conda/core/solve.py
+++ b/conda/core/solve.py
@@ -15,6 +15,7 @@
 from .. import CondaError, __version__ as CONDA_VERSION
 from .._vendor.auxlib.ish import dals
 from .._vendor.boltons.setutils import IndexedSet
+from ..base.constants import UNKNOWN_CHANNEL
 from ..base.context import context
 from ..common.compat import iteritems, itervalues, odict, string_types, text_type
 from ..common.constants import NULL
@@ -509,25 +510,31 @@ def solve_for_transaction(self, deps_modifier=NULL, prune=NULL, ignore_pinned=NU
                 #   History right now. Do we need to include other categories from the solve?
 
         if context.notify_outdated_conda and not context.quiet:
-            conda_newer_spec = MatchSpec('conda >%s' % CONDA_VERSION)
-            if not any(conda_newer_spec.match(prec) for prec in link_precs):
-                conda_newer_records = sorted(
-                    SubdirData.query_all(conda_newer_spec, self.channels, self.subdirs),
-                    key=lambda x: VersionOrder(x.version)
-                )
-                if conda_newer_records:
-                    latest_version = conda_newer_records[-1].version
-                    print(dedent("""
+            current_conda_prefix_rec = PrefixData(context.conda_prefix).get('conda', None)
+            if current_conda_prefix_rec:
+                channel_name = current_conda_prefix_rec.channel.canonical_name
+                if channel_name == UNKNOWN_CHANNEL:
+                    conda_newer_spec = MatchSpec('conda >%s' % CONDA_VERSION)
+                else:
+                    conda_newer_spec = MatchSpec('%s::conda >%s' % (channel_name, CONDA_VERSION))
+                if not any(conda_newer_spec.match(prec) for prec in link_precs):
+                    conda_newer_records = sorted(
+                        SubdirData.query_all(conda_newer_spec, self.channels, self.subdirs),
+                        key=lambda x: VersionOrder(x.version)
+                    )
+                    if conda_newer_records:
+                        latest_version = conda_newer_records[-1].version
+                        print(dedent("""
 
-                    ==> WARNING: A newer version of conda exists. <==
-                      current version: %s
-                      latest version: %s
+                        ==> WARNING: A newer version of conda exists. <==
+                          current version: %s
+                          latest version: %s
 
-                    Please update conda by running
+                        Please update conda by running
 
-                        $ conda update -n base conda
+                            $ conda update -n base conda
 
-                    """) % (CONDA_VERSION, latest_version), file=sys.stderr)
+                        """) % (CONDA_VERSION, latest_version), file=sys.stderr)
 
         return UnlinkLinkTransaction(stp)
 


Test patch: