Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[bug] Channel overriding inconsistent between build / create / graph #15791

Closed
docbrown1955 opened this issue Mar 1, 2024 · 6 comments · Fixed by #15794
Closed

[bug] Channel overriding inconsistent between build / create / graph #15791

docbrown1955 opened this issue Mar 1, 2024 · 6 comments · Fixed by #15794
Assignees
Milestone

Comments

@docbrown1955
Copy link

docbrown1955 commented Mar 1, 2024

Environment details

  • Operating System+version: W11
  • Compiler+version: MSVC192
  • Conan version: 2.0.17
  • Python version: 3.11

Steps to reproduce

  1. Have a recipe with user & channel defined explicitely
  2. Call conan build / conan create or conan graph info on the recipe, overriding the channel using --channel=test
  3. The behavior is different in all cases

Logs

Create command works fine, overrides the channel accordingly and finishes successfully. I'm not sure what is the expected behavior as for the three commands the behavior is different (should it fail ? always ? only when user is not provided ?).

I'm aware that using the channel is not particularly recommended. I'm using it to automate testing of conan workflows & versioning, setting the channel provides a simple way to provide a clean test setup for each workflow.

Build command dramatically fails:

Expand log
conan build . --channel=test

======== Input profiles ========
Profile host:
[settings]
arch=x86_64
build_type=Debug
compiler=msvc
compiler.cppstd=17
compiler.runtime=dynamic
compiler.runtime_type=Debug
compiler.version=192
os=Windows
[conf]
tools.cmake.cmaketoolchain:generator=Ninja

Profile build:
[settings]
arch=x86_64
build_type=Release
compiler=msvc
compiler.cppstd=14
compiler.runtime=dynamic
compiler.runtime_type=Release
compiler.version=192
os=Windows
[conf]
tools.cmake.cmaketoolchain:generator=Ninja

ERROR: Traceback (most recent call last):
  File "D:\conan_env\Lib\site-packages\conan\cli\cli.py", line 280, in main
    cli.run(args)
  File "D:\conan_env\Lib\site-packages\conan\cli\cli.py", line 190, in run
    command.run(self._conan_api, args[0][1:])
  File "D:\conan_env\Lib\site-packages\conan\cli\command.py", line 126, in run
    info = self._method(conan_api, parser, *args)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "D:\conan_env\Lib\site-packages\conan\cli\commands\build.py", line 48, in build
    deps_graph = conan_api.graph.load_graph_consumer(path, args.name, args.version,
                 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "D:\conan_env\Lib\site-packages\conan\api\subapi\graph.py", line 142, in load_graph_consumer
    root_node = self._load_root_consumer_conanfile(path, profile_host, profile_build,
                ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "D:\conan_env\Lib\site-packages\conan\api\subapi\graph.py", line 24, in _load_root_consumer_conanfile
    conanfile = app.loader.load_consumer(path,
                ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "D:\conan_env\Lib\site-packages\conans\client\loader.py", line 161, in load_consumer
    if str(ref):
       ^^^^^^^^
  File "D:\conan_env\Lib\site-packages\conans\model\recipe_ref.py", line 62, in __str__
    assert self.user
AssertionError

ERROR:

Graph info command fails with a nice error message:

Expand log
conan graph info . --channel=test
ERROR: Can't specify --channel without --user

NB: Overriding the user on the command line as well using --user=barbarian works as expected and corrects the issues.

@memsharded memsharded self-assigned this Mar 1, 2024
@memsharded
Copy link
Member

Hi @docbrown1955

Thanks for your report
I am not sure this works with create, the following test fails:

def test_user_channel_override():
    c = TestClient()
    conanfile = textwrap.dedent("""
        from conan import ConanFile
        class SayConan(ConanFile):
            name = "pkg"
            version = "0.1"
            user = "user"
            channel = "channel"
        """)

    c.save({"conanfile.py": conanfile})
    c.run("create . --channel=testing")
   # ERROR:
   # ERROR: Package recipe with channel testing!=channel

Can you please check it?

@docbrown1955
Copy link
Author

docbrown1955 commented Mar 1, 2024

Hi @memsharded,

You are right, I did the test on a recipe that did not have the channel defined (while I thought it had one). So build and create are consistent and prevent overriding the channel through the CLI.

The issue remaining is therefore that graph info does not accept the channel on the command line without the user (even if no channel is defined in the recipe) and outputs the following error:

ERROR: Can't specify --channel without --user

@docbrown1955
Copy link
Author

docbrown1955 commented Mar 1, 2024

So let's say there is a recipe with a user defined as "my_user" and no channel, the graph info command requires to specify the user again (exactly) through the command line if specifying a channel, which is not the case for the build and create commands:

conan graph info . --channel=my_channel --user=my_user

@memsharded
Copy link
Member

The issue remaining is therefore that graph info does not accept the channel on the command line without the user (even if no channel is defined in the recipe) and outputs the following error:

That is correct. Using channel but not user is not allowed, there were some complexities to maintain compatibility in the server sides, it would be breaking, so it is not allowed.

So let's say there is a recipe with a user defined as "my_user" and no channel, the graph info command requires to specify the user again (exactly) through the command line if specifying a channel, which is not the case for the build and create commands:

Then, this we want indeed to check it, I'll try to reproduce in a test.

@memsharded
Copy link
Member

memsharded commented Mar 1, 2024

Not sure about that either 😅

def test_graph_info_user():
    """
    https://github.com/conan-io/conan/issues/15791
    """
    c = TestClient()
    conanfile = textwrap.dedent("""
        from conan import ConanFile
        class Pkg(ConanFile):
            name = "pkg"
            version = "0.1"
            user = "user"
        """)

    c.save({"conanfile.py": conanfile})
    c.run("graph info .")
    assert "pkg/0.1@user" in c.out

UPDATE: Sorry, now I got it. adding

c.run("graph info . --channel=channel")
assert "pkg/0.1@user/channel" in c.out

Makes it fail

@memsharded memsharded added this to the 2.2.0 milestone Mar 1, 2024
@memsharded
Copy link
Member

Found the issue, was a too early argument check, I have moved it later to allow this: #15794, it will be in next 2.2

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants