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

Unable to use variable in keyword more than once : Variable '${arg1}' not found. #95

Open
Avnish-Dewan opened this issue Jun 1, 2023 · 6 comments
Labels
bug Something isn't working

Comments

@Avnish-Dewan
Copy link

Hi,
I am facing an issue while using the variables more than once i.e. If I use a variable more than once in a keyword, it throws an error "Variable '${arg1}' not found.", whereas the first the variable is used , it works fine. I've attached the screenshots of the log files also:
image
image

Code:

*** Settings ***
Library            GeventLibrary

*** Test Cases ***
Example Test
    Log                 Hello
    Create Gevent Bundle    alias=alias1
    Add Coroutine       Task1  123  alias=alias1
    Add Coroutine       Task2   alias=alias1
    
    ${values}=          Run Coroutines    alias=alias1
    Log Many            @{values}

*** Keywords ***
Task1
    [Arguments]     ${arg1}
    Log    Task 1 started
    Log     ${arg1}
    Sleep    2
    Log     ${arg1}

Task2
    Log    Task 2 started
    Sleep    3
    Log    Task 2 finished
    RETURN   Task2

Here is the trace log for the error:

Traceback (most recent call last):
  File "src\\gevent\\greenlet.py", line 908, in gevent._gevent_cgreenlet.Greenlet.run
  File "C:\Users\User\AppData\Local\Programs\Python\Python311\Lib\site-packages\robot\libraries\BuiltIn.py", line 1853, in run_keyword
    return kw.run(self._context)
           ^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\User\AppData\Local\Programs\Python\Python311\Lib\site-packages\robot\running\model.py", line 77, in run
    return KeywordRunner(context, run).run(self)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\User\AppData\Local\Programs\Python\Python311\Lib\site-packages\robot\running\bodyrunner.py", line 76, in run
    return runner.run(step, context, self._run)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\User\AppData\Local\Programs\Python\Python311\Lib\site-packages\robot\running\userkeywordrunner.py", line 68, in run
    return_value = self._run(context, kw.args, result)
                   ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\User\AppData\Local\Programs\Python\Python311\Lib\site-packages\robot\running\userkeywordrunner.py", line 99, in _run
    raise exception
robot.errors.UserKeywordExecutionFailed: Variable '${arg1}' not found.
2023-06-01T10:36:28Z <Greenlet at 0x20909be8cc0: <bound method _RunKeyword.run_keyword of <robot.libraries.BuiltIn.BuiltIn object at 0x0000020908457B90>>('Task1', '123', '456')> failed with UserKeywordExecutionFailed
@eldaduzman
Copy link
Owner

Hi @Avnish-Dewan
What version of robotframework do you use?

@Avnish-Dewan
Copy link
Author

Hi @eldaduzman
The RF version i am using is : Robot Framework 6.0.2 (Python 3.11.3 on win32)

@eldaduzman
Copy link
Owner

@Avnish-Dewan

Ok, it seems like the problem is when you have 2 coroutines running concurrently and then the robotframework context doesn't necessarily fit the currently running coroutine.

In your case, the executed coroutine is task1 but the context is task2.

A quick fix is to use global variables, or avoid using the same arg more than once per keyword.

In the long run I need to think of a why to safely ensure the robotframework context preservation between the keywords.

This is a high quality bug :)

@eldaduzman eldaduzman added the bug Something isn't working label Jun 15, 2023
@Lakitna
Copy link

Lakitna commented Dec 20, 2023

I just ran into the same issue.

The workarounds don't work in my case, as I have a fair amount of complexity that I can't rewrite just for performance gains by running async.

For me, this means that, for now, I'll bail on doing anything async :(

@eldaduzman
Copy link
Owner

@Lakitna I understand, the solution is not simple, it requires maintaining an entire copy of rbf context for all coroutines, I'm working on it, it will take time.

@Lakitna
Copy link

Lakitna commented Dec 20, 2023

@eldaduzman That makes sense :)
In the meantime, I can work around the performance issues I'm facing with more pipeline time, so I'll wait patiently.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

3 participants