Skip to content

Embedded arguments are not passed as objects when executed with Run Keyword or its variants #1595

Closed

Description

@spooning

Originally submitted to Google Code by @jussimalinen on 29 Nov 2013

This does not work:

*** Test Cases ***
Example
    ${foo} =      Evaluate    {'a':42}
    Huu '${foo}'      # Works
    Run Keyword       Huu '${foo}'      # Does not work
    Run Keyword If    True    Huu '${foo}'      # Does not work either

*** Keywords ***
Huu '${foo}'
    Log    ${foo['a']}    WARN

This has never worked. Run Keyword variants accept the name of the keyword to execute to be specified as a variable, and thus the variable part is resolved too early. In the above example Run Keyword ends up running keyword Huu '{'a': 42}', and thus the ${foo} argument passed to the keyword will be string {'a': 42}.

Activity

  1. pekkaklarck commented on Mar 5, 2019

    @pekkaklarck
    Member

    Implementing #2699 would be a workaround for this problem with lists and dictionaries (and a useful feature in general). It's currently targeted for RF 3.2, but I'm not sure do I have time to look at it so it may end up being descoped like it was from RF 3.1. Anyone else interested to implement it? It shouldn't cause backwards compatibility problems so could possibly be added already in RF 3.1.2.

  2. pekkaklarck commented on Oct 17, 2019

    @pekkaklarck
    Member

    Issue #3278 has more potential than #2699 and would help with this problem as well. Neither of these issues would help with custom object but Python base types, including containers, ought to work.

  3. pekkaklarck commented on Oct 17, 2019

    @pekkaklarck
    Member

    I guess this could be fixed properly by looking is there a keyword that matches the given keyword name before replacing variables and only replacing variables if there isn't. Would make the logic in Run Keyword somewhat more complicated but ought to be doable. Anyone interested to look at it?

  4. MariuszJanczura commented on Oct 18, 2019

    @MariuszJanczura

    I could look at it but I would need to have more details regarding that and some time I suppose :)

  5. pekkaklarck commented on Oct 18, 2019

    @pekkaklarck
    Member

    I think the steps would be these:

    1. Change run_keyword (and if we can make this work, all keywords that use it) to not resolve variables in arguments at all. That as easy as using @run_keyword_variant(resolve=0).

    2. Try finding a keyword without replacing variables in name. If that fails, try replacing variables.

    3. Some care must be taken to handle name that is defined as @{list} variable (i.e. when it contains also arguments). Probably should just replace variables in that case.

  6. pekkaklarck commented on Oct 18, 2019

    @pekkaklarck
    Member

    Some code examples (untested) that could be useful:

    match = search_variable(name)
    if not match:
        # did not contain variables at all, act accordingly
    elif match.is_list_variable:
        # list variable - need to replace it and use the first value as name
        args = self._variables.replace_list([name] + args, replace_until=1)
        name = args.pop(0)
    else:
        # value contains variable, act accordingly
  7. pekkaklarck commented on Sep 9, 2022

    @pekkaklarck
    Member

    When debugging and fixing #4453, I got an idea how to implement this feature as well. The basic idea was this:

    • Don't replace variables in name passed to Run Keyword and to keywords using it internally.
    • In Run Keyword get a runner based on the name without replacing variables.
    • Replace variables in the name if the runner we got doesn't handle embedded arguments. Otherwise use the name as-is.

    This means that with normal keywords variables in the name are resolved normally before actually finding the runner to execute them. With embedded arguments variables are not resolved so the runner that is found will take care of them of them properly.

    The basic idea wasn't too complicated and I got a prototype working fast. A problem was that changing all run keyword variants so that they don't resolve the name caused various smaller and bigger issues that needed to be handled. Those problems ought to now be fixed and the resulting code looks so good that this can be finalized still before RF 5.1.

  8. added this to the v5.1 milestone on Sep 9, 2022
  9. changed the title [-]Embedded arguments are not passed as objects when executed with Run keyword variants[/-] [+]Embedded arguments are not passed as objects when executed with `Run Keyword` or its variants[/+] on Sep 10, 2022
  10. pekkaklarck commented on Sep 10, 2022

    @pekkaklarck
    Member

    The change that BuiltIn.run_keyword nowadays resolves the name argument itself means that behavior changes if it is called programmatically. This only affects situations where the name contains variables or escapes and keyword names are not likely to contain them. Anyway, need to mention this small backwards incompatibility in the release notes.

  11. added theissue type on Dec 9, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    Projects

    No projects

      Milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions