You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Embedded arguments are not passed as objects when executed with Run Keyword or its variants #1595
*** 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}.
Reacted by djaromir, jumois and Andreas Kaltenleitner
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.
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.
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?
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).
Try finding a keyword without replacing variables in name. If that fails, try replacing variables.
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.
Some code examples (untested) that could be useful:
match=search_variable(name)
ifnotmatch:
# did not contain variables at all, act accordinglyelifmatch.is_list_variable:
# list variable - need to replace it and use the first value as nameargs=self._variables.replace_list([name] +args, replace_until=1)
name=args.pop(0)
else:
# value contains variable, act accordingly
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.
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
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.
Activity
pekkaklarck commentedon Mar 5, 2019
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.
pekkaklarck commentedon Oct 17, 2019
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.
pekkaklarck commentedon Oct 17, 2019
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 Keywordsomewhat more complicated but ought to be doable. Anyone interested to look at it?MariuszJanczura commentedon Oct 18, 2019
I could look at it but I would need to have more details regarding that and some time I suppose :)
pekkaklarck commentedon Oct 18, 2019
I think the steps would be these:
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).Try finding a keyword without replacing variables in
name. If that fails, try replacing variables.Some care must be taken to handle
namethat is defined as@{list}variable (i.e. when it contains also arguments). Probably should just replace variables in that case.pekkaklarck commentedon Oct 18, 2019
Some code examples (untested) that could be useful:
pekkaklarck commentedon Sep 9, 2022
When debugging and fixing #4453, I got an idea how to implement this feature as well. The basic idea was this:
Run Keywordand to keywords using it internally.Run Keywordget a runner based on the name without replacing variables.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.
[-]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[/+]pekkaklarck commentedon Sep 10, 2022
The change that
BuiltIn.run_keywordnowadays resolves thenameargument 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.