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

Repository version user-entered options order fix #847

Merged
merged 1 commit into from
Feb 22, 2024

Conversation

MichalPysik
Copy link
Member

@MichalPysik MichalPysik commented Dec 7, 2023

The order in which the user enters options (--version, --repository, ..) no longer matters for
'pulp repository version' commands, since all API calls are now deferred to after the
options' callbacks are processed.

closes #650

Review Checklist:

  • An issue is properly linked. [feature and bugfix only]
  • Tests are present or not feasible.
  • Commits are split in a logical way (not historically).

@MichalPysik
Copy link
Member Author

I don't know whether that's needed, but if you want me to add a simple test case, I can insert a pulp {plugin} repository version show somewhere in the existing tests.

@lubosmj
Copy link
Member

lubosmj commented Dec 7, 2023

You may sneak a repository version destroy call at the end of an existing test, like: pulp file repository version destroy --version 1 --repository=repo and change the order of some of the used resource lookups, like:

expect_succ pulp rpm repository version repair --repository "cli_test_rpm_repository" --version 1
,
expect_succ pulp container repository copy-manifest --repository "cli_test_dest_container_repository" --source "cli_test_source_container_repository" --version "1" --media-type "application/vnd.docker.distribution.manifest.v2+json"
.

With this, we will verify whether your fix works globally or not.

@MichalPysik MichalPysik force-pushed the repository_argument_order_fix branch 2 times, most recently from 202cfbc to 09f90d9 Compare December 11, 2023 12:28
@MichalPysik MichalPysik changed the title Resource lookup option --repository is now an eager parameter. Option --repository is now an eager parameter. Dec 11, 2023
@@ -0,0 +1 @@
Option (also resource lookup option) --repository is now an eager (high priority) parameter.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A user reading through the changelog would have no idea what this means.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@daviddavis thanks, you're right. Is the new one any better?

@@ -863,11 +863,13 @@ def _type_callback(ctx: click.Context, param: click.Parameter, value: t.Optional
help=_("Name of the repository"),
callback=lookup_callback("name", PulpRepositoryContext),
expose_value=False,
is_eager=True,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not convinced, this is a nice solution, because it put's --repository on the same level as --help.
I believe we have ways to specify repository versions in a single option with the export code.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would that mean that the help message will not be printed if I use both --repository and --help?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's sure something to test. But I'm hesitant to call "--repository" that special.

Copy link
Member Author

@MichalPysik MichalPysik Dec 15, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@mdellweg I though so based on the documentation, but --help still acts as it should. Even if I use --repository with an invalid repository name, and put --help AFTER --repository, I still only get the help message printed.

Maybe --help is not only eager, but also has some special property in Click.

Copy link
Member Author

@MichalPysik MichalPysik Dec 15, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

"repo" is a repository that actually exists, "repo2" is nonexistent

pulp file repository version show --repository repo --help
Usage: pulp file repository version show [OPTIONS]

  Show details of a repository version.

Options:
  --repository-href TEXT  HREF of the repository
  --repository TEXT       A resource to look for identified by <name> or by
                          <href>.
  --version INTEGER       Repository version number
  --help                  Show this message and exit.
pulp file repository version show --repository repo2 --help
Usage: pulp file repository version show [OPTIONS]

  Show details of a repository version.

Options:
  --repository-href TEXT  HREF of the repository
  --repository TEXT       A resource to look for identified by <name> or by
                          <href>.
  --version INTEGER       Repository version number
  --help                  Show this message and exit.

Also, adding --version ANYWHERE doesn't change the outcomes.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OK, eager is not the solution, because the real issue in disguise is that _version_callback is evaluating the repository context prematurely (before all options have been seen), by accessing it's pulp_href. Leading to api calls before we even know the command is syntactically correct.
Instead, it should hook the contexts up lazily.

@MichalPysik MichalPysik force-pushed the repository_argument_order_fix branch from 09f90d9 to 3a999ae Compare December 15, 2023 09:01
@@ -863,11 +863,13 @@ def _type_callback(ctx: click.Context, param: click.Parameter, value: t.Optional
help=_("Name of the repository"),
callback=lookup_callback("name", PulpRepositoryContext),
expose_value=False,
is_eager=True,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OK, eager is not the solution, because the real issue in disguise is that _version_callback is evaluating the repository context prematurely (before all options have been seen), by accessing it's pulp_href. Leading to api calls before we even know the command is syntactically correct.
Instead, it should hook the contexts up lazily.

@MichalPysik MichalPysik force-pushed the repository_argument_order_fix branch from 3a999ae to d0a9e41 Compare January 22, 2024 10:24
@MichalPysik MichalPysik force-pushed the repository_argument_order_fix branch from d0a9e41 to 51c8564 Compare February 1, 2024 16:14
@MichalPysik MichalPysik changed the title Option --repository is now an eager parameter. Repository version user-entered options order fix Feb 1, 2024
@MichalPysik MichalPysik requested a review from mdellweg February 1, 2024 16:16
@MichalPysik MichalPysik force-pushed the repository_argument_order_fix branch 3 times, most recently from 7f96cbc to dcbf95f Compare February 12, 2024 12:14
@MichalPysik MichalPysik requested a review from mdellweg February 12, 2024 12:51
@MichalPysik MichalPysik force-pushed the repository_argument_order_fix branch 3 times, most recently from 493b594 to 6cc4258 Compare February 15, 2024 09:44
@mdellweg mdellweg removed the request for review from gerrod3 February 15, 2024 11:28
@MichalPysik MichalPysik force-pushed the repository_argument_order_fix branch from 6cc4258 to f67ef63 Compare February 16, 2024 11:51
@MichalPysik MichalPysik force-pushed the repository_argument_order_fix branch 10 times, most recently from 15aa4b6 to c537cbb Compare February 19, 2024 14:34
@MichalPysik MichalPysik force-pushed the repository_argument_order_fix branch 4 times, most recently from 0e7552b to f6ded88 Compare February 22, 2024 12:04
The order in which the user enters options (--version, --repository, ..) no longer matters for
'pulp <plugin> repository version' commands, since all API calls are now deferred to after the
options' callbacks are processed.

closes pulp#650
@MichalPysik MichalPysik force-pushed the repository_argument_order_fix branch from f6ded88 to 807416a Compare February 22, 2024 12:35
@mdellweg mdellweg merged commit 9a061aa into pulp:main Feb 22, 2024
20 checks passed
@MichalPysik MichalPysik deleted the repository_argument_order_fix branch February 26, 2024 10:08
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 this pull request may close these issues.

It looks like option order can matter in unintuitive ways.
5 participants