Nivedita Deshmukh
Nivedita Deshmukh

Reputation: 309

In yaml file, variable's original value is getting loose while reusing the configuration

Steps to reproduce:

variables:
  my_pwd: 'Kt^$$&^dg#%o4Zwcat9knS)S#W'
  short_wait: 8

common_blocks:
  - &prod_my_pwd
    name: MY_password
    type xpath //*[@id="login-pwd"]: $my_pwd
    click: xpath //*[@id="login-sub"]
    wait: $short_wait

uitest:
 - *prod_my_pwd

This is my gramextest script, where In the Yaml file where I am Reusing Configuration

The variable 'my_pwd' has $ symbol in it and to handle valueerror in the case if $ symbol available in the string I am adding $$ instead of $ (and the gramex -> config.py -> _substitute_variable() function handle this escaping of $ case value error)

but still in my script it failing and returning exception -> ValueError: Use $$ instead of $ in Ve5$&^fh#%o4Znjtv9kmH)H#W So when I debug the gramex python function _substitute_variable() I got to know

  1. This is working fine at first place when I am calling/using variable $my_pwd
  2. But this is failing when I am Reusing the configuration which is - *prod_my_pwd

And the reason why its failing at 2nd place is - at the first time execution of $my_pwd it replacing its original value and storing the returned val of _substitute_variable() and hence at the place of Reusing configuration its not getting the original value (with $$) of 'my_pwd' and the function _substitute_variable() returning value error : ValueError: Use $$ instead of $ in Ve5$&^fh#%o4Znjtv9kmH)H#W

I am wondering how the $my_pwd loosing its original value and hence while Reusing configuration I am not getting original defined variable's value.

Expected behavior: variable should not loose its original defined value while reusing unless and until its explicitly change/replace in script later

Environment: Gramex version: oldest to 1.80.0

Upvotes: 0

Views: 37

Answers (1)

S Anand
S Anand

Reputation: 11948

Here's a sample configuration that reproduces the issue:

variables:
  my_pwd: '$$&'

url:
  a:
    pattern: /a
    handler: FunctionHandler
    kwargs: &alpha
      function: str
      args: $my_pwd
  b:
    pattern: /b
    handler: FunctionHandler
    kwargs: *alpha

With this configuration, Gramex fails to start. This is a bug.

The simplest workaround is to avoid $ in the password until the bug is fixed.

Upvotes: 0

Related Questions