-
Notifications
You must be signed in to change notification settings - Fork 16
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
Validate full model name in the deprecate model flow #427
Conversation
Apply Sweep Rules to your PR?
|
gto/registry.py
Outdated
@@ -421,6 +421,7 @@ def deprecate( | |||
author: Optional[str] = None, | |||
author_email: Optional[str] = None, | |||
) -> Optional[Deprecation]: | |||
self._check_args(name=name, version=None, rev=rev, deprecate_model=True) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
let's just do assert_fullname_is_valid(name)
if need to validate the name and nothing else
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks @tapadipti ! I left a comment + I think we would need a test for this. |
Codecov ReportAll modified and coverable lines are covered by tests ✅
📢 Thoughts on this report? Let us know!. |
Thanks @shcheklein. I've addressed your comments. For the test, I ran it locally by calling it from a There are more validations to be added. Eg, currently it accepts |
thanks @tapadipti ! it looks good, but it seems we need to fix the test. Please see the checks above. |
The error message returned by the name validation functions is quite long. So it looks like a new line character (
Is there a way to turn off this automatic addition? I was not adding this To resolve this, I've now added the However, I'm not sure if some other products with dependencies on GTO could break due to this (if they're expecting a string without this |
@tapadipti I think it's better to not alter the behavior, but rather fix test to be more lax on comparison. E.g. remove all |
…evert name check error message
@shcheklein So this is failing for Windows only - so it must be something to do with Windows convention for line endings (not the first time Windows got me stuck for so long 😞). Still not sure how to resolve this - will try to figure out. But I think it's better to just add the line break at the end of the sentence (like I tried before).
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The GTO CLI test framework is fragile (and IMO a lot of these tests are not actually useful either) since all of the tests are hard coded to check for fixed output.
The issue that shows up here is that the underlying test for CLI commands uses click.CliRunner
which will implements line wrapping at a fixed maximum content width of 80. Wrapped lines will also be split using the platform specific line ending (which is CRLF on windows and not just LF). This was a non-issue for all of the other existing tests up to now (purely by coincidence) since none of them generate a line longer than 80 characters.
Adjusting the test framework to strip all newlines and replace them with spaces is probably not the right way to go since the newlines are explicitly expected output in all of the other existing tests (where the split lines are significant).
The fix here should be to just manually handle the line wrapping at 80 characters in the new test like
def test_deprecate_artifact(repo_with_commit: str):
expected = os.linesep.join(
[
(
"❌ Invalid value 'a4!'."
" Only letters, numbers, '_', '-', '/' are allowed. Value "
),
(
"must be of len >= 2 and must start and end with a letter or"
" a number.\n"
),
]
)
_check_failing_cmd(
"deprecate",
["-r", repo_with_commit, "a4!"],
expected,
)
(this should fix the test failures and should not require modifying _check_output_exact_match
at all in this PR)
ideally in the long term all of the tests should be updated to work off of a list of expected lines instead of a single hard coded expected string, and then the check functions would do something like
which will work regardless of platform/line ending, and it will account for commands where the newlines in output are significant Should also note that this does not account for the fact that click will also automatically add indentation depending on content and context which may end up causing similar issues in the future (so exact string comparison in tests would break due to leading tabs or spaces instead of newlines) |
@pmrowla Yes.
I wish this comment was here yesterday or earlier today. Figured it out the hard way today. Have fixed it by doing replace differently for Windows. Which I don't like. So I'll revert to what you've suggested - which is pretty much what I had here and here. @shcheklein Can you pls confirm you're ok with this - coz you'd earlier suggested |
The problem with this is that this is applied to the tests for every GTO command and it strips the line breaks in places where the test behavior is actually significant, i.e. when the expected output is explicitly
Stripping/replacing all the line breaks means the test would now pass if the CLI command outputs
(which is why I suggested that the long term solution should be that CLI output tests in GTO compare lists of expected lines and not a single expected string) |
@pmrowla I agree with you - it's better not to strip the line breaks. I've made a new commit reverting to an earlier state where I added an explicit line break in the error message to handle the 80 character limit. The suggestion you provided in your comment works for the name @shcheklein pls confirm if this is ok. |
This is true, but we would hit the issue even with the manual line break if we changed the test to use a longer name. I would prefer to not have the manual line breaks in the exception message. The line wrapping is handled by the UI rendering library ( IMO these kinds of fragile UI tests for CLI output are not actually useful at all. It would be better to test that the expected exception is raised by the underlying call. Basically, GTO tests should only be testing GTO functionality. But right now, the CLI tests are causing issues because in addition to testing GTO functionality they are also testing how click line wraps a given exception message. The click formatting behavior is not actually relevant to whether or not GTO works properly (and click's line wrapping is tested in click itself). |
@pmrowla I tried removing the manual line breaks in the exception message, as you suggested. But it's not working - it looks like the space between Summary of error:When I use your suggested code for the test (in this commit), I get the following mismatch between the actual and expected values.
If I use a
From what I saw yesterday, this (stripping) does not happen in ubuntu and macos, so I can't just remove the space from the expected value (else the test will fail in ubuntu and macos). I can treat Windows differently (similar to how I did here), but imo that's a terrible idea. So my only option now is to revert to adding the manual line break in the exception message (or to improve how the tests are written, which I don't want to make part/dependency of this PR). |
Edit: I see there are also issues related to spacing, so I don't think this alone will help much. Disregard. |
We should just remove this CLI test entirely and test the underlying behavior in with pytest.raises(ValidationError):
api.deregister(...) # call deregister with an invalid name |
For now, I'm removing the test. I've created an issue to improve tests, and we can add a test for the deprecate model action with invalid model name there. cc @pmrowla @shcheklein @dberenbaum |
@pmrowla Can you ptal at this comment and re-review this PR. I can't merge the PR without you accepting the change. |
Earlier, the model name was not being validated for the deprecate model action. It was getting validated for all other actions including the unassign and deregister actions (which are variations of the deprecate action).
Resolves iterative/dvc#9821 (comment)