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

fix(api): better error message for non-string variable names and min/max validation adjustment #14938

Merged
merged 2 commits into from
Apr 18, 2024

Conversation

jbleon95
Copy link
Contributor

Overview

Closes AUTH-303.

This PR fixes an issue where if a non-string was given for a variable name, it would fail with an unhelpful error message instead of raising the proper error saying that the variable name was not a string. This was due to the uniqueness check which was not checking if the variable name was a string, which could lead to unhashable type errors for certain values (like dictionaries).

The other part of this PR is a small adjustment to the validation for minimum and maximum. Previously we would not allow minimum and maximum values that were the same. After talk with the Authorship team, it was decided that these values would be allowed, since there is one valid option for the parameter. This matches with the current behavior of allowing only one choice parameter. The error message "Maximum must be greater than the minimum" was kept however, so as not to point users in this direction.

Test Plan

Tested that this protocol fails with a "Variable name must be a string." error

metadata = {
    "protocolName": "RTP variable name dict",
}
requirements = {"robotType": "OT-2", "apiLevel": "2.18"}
def add_parameters(parameters):
    parameters.add_int(
        display_name="int 1",
        variable_name={},
        default=1,
        minimum=1,
        maximum=3,
    )

def run(context):
    for variable_name, value in context.params.get_all().items():
        context.comment(f"variable {variable_name} has value {value}")

and this following PR passes analysis

metadata = {
    "protocolName": "RTP Parameters with Min=Max",
}
requirements = {"robotType": "OT-2", "apiLevel": "2.18"}

def add_parameters(parameters):
    parameters.add_int(
        display_name="Display Name",
        variable_name="int_var",
        default=5,
        minimum=5,
        maximum=5,
    )
    parameters.add_float(
        display_name="Display Name",
        variable_name="float_var",
        default=5.0,
        minimum=5.0,
        maximum=5.0,
    )


def run(context):
    for variable_name, value in context.params.get_all().items():
        context.comment(f"variable {variable_name} has value {value}")

Changelog

  • Fix uniqueness check for variable names to ignore non-string values (those will be caught on a later validation check)
  • Allow minimum and maximum to be the same for int and float parameters

Review requests

Risk assessment

Low

@jbleon95 jbleon95 requested a review from a team as a code owner April 17, 2024 19:05
@jbleon95 jbleon95 requested review from y3rsh and sanni-t April 17, 2024 19:09
@jbleon95 jbleon95 merged commit 1a4492b into edge Apr 18, 2024
26 checks passed
@jbleon95 jbleon95 deleted the rtp_variable_name_and_min_max_validation branch April 18, 2024 17:40
Carlos-fernandez pushed a commit that referenced this pull request May 20, 2024
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.

None yet

2 participants