Skip to content

Document that Get Variable Value and Variable Should (Not) Exist do not support named-argument syntax #5235

Closed

Description

@Mkinen

Hi,

I noticed that I am not able to pass default argument for Get Variable Value from BuiltIn as keyword argument. I.e. the following does not provide expected result: ${result} BuiltIn.Get Variable Value ${MY_VARIABLE} default=My Default

One would expect ${result} to have My Default as return if ${MY_VARIABLE} does not exist. Instead default=My Default is returned.

get_variable_value_example

I didn't find any notion of this functionality anywhere and if the keyword works as expected, I would assume that this was mentioned in the documentation.

This was tested with version 7.0.

Activity

  1. a-matta commented on Oct 13, 2024

    @a-matta

    The decorator @run_keyword_variant(resolve=0) atop the get_variable_value implementation ensures a NullArgumentResolver is used intead of a NamedArgumentResolver. Thus the entire string is handled as a value (positional parameter). Seems by design (I don't know). The docstring indicates correctly.

    https://robotframework.org/robotframework/latest/libraries/BuiltIn.html#Get%20Variable%20Value
    image

    Seems the intention is to use this without the default= prefix. ¯\_(ツ)_/¯

  2. pekkaklarck commented on Oct 16, 2024

    @pekkaklarck
    Member

    @a-matta is right about why this happens. The mentioned @run_keyword_variant decorator is used to tell Robot not to replace variables in arguments. The reason why it's done is that otherwise using this keyword with a non-existing variable would fail already when arguments would be resolved.

    I'm not sure has it even occurred to me earlier that not resolving arguments also disables the named argument syntax. That's rather annoying and should be fixed. The whole system for marking arguments not to be resolved is pretty bad and we have #2190 about fixing that. I'll add a comment to that issue about this problem.

    Because the problem won't be fixed in the near future, I believe it's best to document this behavior in the keyword documentation. I'll check are there other keywords in BuiltIn that would need such a note as well.

  3. changed the title [-]"Get Variable Value" does not support keyword argument for "default"[/-] [+]Document that `Get Variable Value` and `Variable Should (Not) Exist` do not support named-argument syntax[/+] on Oct 16, 2024
  4. self-assigned this
    on Oct 16, 2024
  5. pekkaklarck commented on Oct 16, 2024

    @pekkaklarck
    Member

    Variable Should Exist and Variable Should Not Exist have a similar situation with their message argument. Also some other keywords are possibly affected, but I doubt they'd in general be used with the named-argument syntax anyway.

  6. added this to the v7.2 milestone on Oct 16, 2024
  7. added a commit that references this issue on Oct 16, 2024
    2c995d7
  8. pekkaklarck commented on Aug 27, 2025

    @pekkaklarck
    Member

    As #5025 demonstrated, various other keywords had the same problem. Instead of adding a note about this to all their docs, I decided to explicitly mark these arguments positional-only. That was done also to keywords that got a note to their docs as part of this issue. Notes were preserved otherwise, but the comment about us hopefully fixing the limitation in the future was removed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Projects

No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions