Repository: conan-io/conan

Issue:
[bug] Stack trace instead of error message with conan alias
### Environment Details (include every applicable attribute)
  * Operating System+version: Ubuntu 20.04.2 LTS
  * Compiler+version: N/A
  * Conan version: 1.34.1
  * Python version: 3.8.8

When creating an alias package that already exists, instead of printing the correct error message you will get a stack trace if the package in question uses python_requires. 

### Steps to reproduce (Include if Applicable)
1. Create a conanfile with the following contents:
```python
from conans import ConanFile
class Test(ConanFile):
    name = "test-python-requires"
    version ="1.0.0"
```
3. Create another conanfile with the following contents:
```python
from conans import ConanFile
class TestPkg(ConanFile):
    python_requires = "test-python-requires/1.0.0"
    name = "test"
    version = "1.0.0"
```
4. Run conan create for both packages. There should be test/1.0.0@ and test-python-requires/1.0.0@ in your cache.
5. Run `conan alias test/1.0.0@ test/2.0.0@` (note that the arguments are backwards)

### Logs (Executed commands with output) (Include/Attach if Applicable)
```
gitpod ~/test $ conan alias test/1.0.0@ test/2.0.0@
Traceback (most recent call last):
  File "/workspace/.pip-modules/lib/python3.8/site-packages/conans/client/command.py", line 2143, in run
    method(args[0][1:])
  File "/workspace/.pip-modules/lib/python3.8/site-packages/conans/client/command.py", line 1763, in alias
    self._conan.export_alias(args.reference, args.target)
  File "/workspace/.pip-modules/lib/python3.8/site-packages/conans/client/conan_api.py", line 94, in wrapper
    return f(api, *args, **kwargs)
  File "/workspace/.pip-modules/lib/python3.8/site-packages/conans/client/conan_api.py", line 1179, in export_alias
    conanfile = self.app.loader.load_basic(alias_conanfile_path)
  File "/workspace/.pip-modules/lib/python3.8/site-packages/conans/client/loader.py", line 39, in load_basic
    return self.load_basic_module(conanfile_path, lock_python_requires, user, channel,
  File "/workspace/.pip-modules/lib/python3.8/site-packages/conans/client/loader.py", line 66, in load_basic_module
    self._pyreq_loader.load_py_requires(conanfile, lock_python_requires, self)
  File "/workspace/.pip-modules/lib/python3.8/site-packages/conans/client/graph/python_requires.py", line 90, in load_py_requires
    py_requires = self._resolve_py_requires(py_requires_refs, lock_python_requires, loader)
  File "/workspace/.pip-modules/lib/python3.8/site-packages/conans/client/graph/python_requires.py", line 104, in _resolve_py_requires
    py_requires_ref = self._resolve_ref(py_requires_ref, lock_python_requires)
  File "/workspace/.pip-modules/lib/python3.8/site-packages/conans/client/graph/python_requires.py", line 125, in _resolve_ref
    self._range_resolver.resolve(requirement, "py_require", update=self._update,
AttributeError: 'PyRequireLoader' object has no attribute '_update'

ERROR: 'PyRequireLoader' object has no attribute '_update'
```


Discussion:

Resolving patch:
diff --git a/conans/client/conan_api.py b/conans/client/conan_api.py
--- a/conans/client/conan_api.py
+++ b/conans/client/conan_api.py
@@ -1166,6 +1166,8 @@ def get_path(self, reference, package_id=None, path=None, remote_name=None):
 
     @api_method
     def export_alias(self, reference, target_reference):
+        self.app.load_remotes()
+
         ref = ConanFileReference.loads(reference)
         target_ref = ConanFileReference.loads(target_reference)
 


Test patch:
diff --git a/conans/test/integration/command/alias_test.py b/conans/test/integration/command/alias_test.py
--- a/conans/test/integration/command/alias_test.py
+++ b/conans/test/integration/command/alias_test.py
@@ -398,6 +398,19 @@ def test_repeated_alias(self):
         client.run("alias Hello/0.X@lasote/channel Hello/0.2@lasote/channel")
         client.run("alias Hello/0.X@lasote/channel Hello/0.3@lasote/channel")
 
+    def test_existing_python_requires(self):
+        # https://github.com/conan-io/conan/issues/8702
+        client = TestClient()
+        client.save({"conanfile.py": GenConanfile()})
+        client.run("create . test-python-requires/0.1@user/testing")
+        client.save({"conanfile.py": """from conans import ConanFile
+class Pkg(ConanFile):
+    python_requires = 'test-python-requires/0.1@user/testing'"""})
+        client.run("create . Pkg/0.1@user/testing")
+        client.run("alias Pkg/0.1@user/testing Pkg/0.2@user/testing", assert_error=True)
+        self.assertIn("ERROR: Reference 'Pkg/0.1@user/testing' is already a package",
+                      client.out)
+
     def test_basic(self):
         test_server = TestServer()
         servers = {"default": test_server}