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

Handle empty input parameter. #158

Merged
merged 3 commits into from
May 27, 2024
Merged

Conversation

Mohammad-nassar10
Copy link
Collaborator

Why are these changes needed?

Related issue number (if any).

Signed-off-by: Mohammad Nassar <[email protected]>
@blublinsky
Copy link
Collaborator

I am not sure what exactly this fixes. Empty params are processed correctly through the set of default vaues

res += f"--{key} "
elif isinstance(value, str):
if value != "":
res += f'--{key}="{value}" '
Copy link
Member

Choose a reason for hiding this comment

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

what if the value has double-quotes in it?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

It shouldn't have double-quotes. For example, the dictionary keys and values should be quoted with single-quote.

Copy link
Member

Choose a reason for hiding this comment

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

What will be if the value is None?

Copy link
Member

Choose a reason for hiding this comment

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

I suggest to use

if len(value) != 0:
   res += f'--{key}="{value}" '

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

It shouldn't be None value here, because if the user keep the input as blank field it will be an empty string. Also len(None) will throw an exception.

Copy link
Collaborator

Choose a reason for hiding this comment

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

+1 Mohhammad

Copy link
Collaborator

@blublinsky blublinsky May 25, 2024

Choose a reason for hiding this comment

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

After thinking about it some more I think it is even simpler. Considering that the code has proper defaults for everything, I thing we can do this:

        for key, value in d.items():
            if str(value) != "":
                if isinstance(value, str):
                    res += f'--{key}="{value}" '
                else:
                    res += f"--{key}={value} "
        return res

So we are just removing parameters with empty value

@Mohammad-nassar10
Copy link
Collaborator Author

The purpose of this is to "ignore" the empty input parameters and don't include them in the command line invocation of the transform so it will use the default values as defined by the library.

.make.versions Outdated Show resolved Hide resolved
.make.versions Outdated Show resolved Hide resolved
res += f"--{key} "
elif isinstance(value, str):
if value != "":
res += f'--{key}="{value}" '
Copy link
Member

Choose a reason for hiding this comment

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

What will be if the value is None?

res += f"--{key} "
elif isinstance(value, str):
if value != "":
res += f'--{key}="{value}" '
Copy link
Member

Choose a reason for hiding this comment

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

I suggest to use

if len(value) != 0:
   res += f'--{key}="{value}" '

res += f"--{key} "
elif isinstance(value, str):
if value != "":
res += f'--{key}="{value}" '
Copy link
Collaborator

Choose a reason for hiding this comment

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

+1 Mohhammad

Signed-off-by: Mohammad Nassar <[email protected]>
Copy link
Member

@roytman roytman left a comment

Choose a reason for hiding this comment

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

LGTM

@roytman roytman merged commit b8395f4 into IBM:dev May 27, 2024
11 checks passed
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.

4 participants