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): raise an error if protocol's defined parameters have duplicate variable names #14888

Merged
merged 1 commit into from
Apr 12, 2024

Conversation

jbleon95
Copy link
Contributor

Overview

Closes AUTH-333.

An unintended behavior was found where protocol analysis would let you have two parameters share the same variable name. Not only would this cause issues reporting them since we key them by variable name, the protocol itself would only use the latter value, leading to unintended behavior. I thought this case would be covered once the parameters would be set, but since they are all stored in a dictionary, that was actually never being encountered since the latest one would overwrite the previous one.

Now we have an explicit check for uniqueness, raising an appropriate error message if you have two (or more, though it'll raise on the second) variable names shared.

Test Plan

Along with unit test coverage, ensured this protocol from the ticket now correctly raises.

metadata = {
    "protocolName": "Multiple RTP Variables with Same Name",
}
requirements = {"robotType": "OT-2", "apiLevel": "2.18"}
just_right: str = "This is a description"
def add_parameters(parameters):
    parameters.add_int(
        display_name="int 1",
        variable_name="variable_a",
        default=1,
        minimum=1,
        maximum=3,
        description=just_right,
    )
    parameters.add_int(
        display_name="int 2",
        variable_name="variable_b",
        default=1,
        minimum=1,
        maximum=3,
        description=just_right,
    )
    parameters.add_int(
        display_name="int 3",
        variable_name="variable_a", # duplicate variable name
        default=1,
        minimum=1,
        maximum=3,
        description=just_right,
    )
def run(context):
    for variable_name, value in context.params.get_all().items():
        context.comment(f"variable {variable_name} has value {value}")

Review requests

Risk assessment

Low, simple bug fix.

@jbleon95 jbleon95 requested review from y3rsh, ecormany and sanni-t April 12, 2024 18:11
@jbleon95 jbleon95 requested a review from a team as a code owner April 12, 2024 18:11
Copy link
Member

@sanni-t sanni-t left a comment

Choose a reason for hiding this comment

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

LGTM!

Copy link
Contributor

@ecormany ecormany left a comment

Choose a reason for hiding this comment

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

Error message looks good. Tested with a sample protocol and it works.

@jbleon95 jbleon95 merged commit efc6bd6 into edge Apr 12, 2024
26 checks passed
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.

3 participants