bruno icon indicating copy to clipboard operation
bruno copied to clipboard

previous value of variable used in JSON body

Open applepies opened this issue 9 months ago • 10 comments

I have checked the following:

  • [X] I use the newest version of bruno.
  • [X] I've searched existing issues and found nothing related to my issue.

Describe the bug

When using variables inside a JSON body, upon executing the request, the body sent contains the previous value of the variable

Repro:

  1. create a new request, POST, https://www.example.com
  2. set the body to JSON and add { "foo": "{{bar}}" } as the body
  3. add a variable bar with value 123
  4. send the request
  5. observe > data {"foo":"123"} in the Timeline
  6. update the value of bar to 1234
  7. send the request again
  8. observe > data {"foo":"123"} in the Timeline
  9. send the request a third time
  10. observe > data {"foo":"1234"} in the Timeline

.bru file to reproduce the bug

example.zip

Screenshots/Live demo link

image image image

applepies avatar May 13 '24 13:05 applepies

I have seen seen similar problem, when trying to set the env variable that is used in the body, with a pre-request script. It appears that the pre request script is NOT preceeding the body construction. The pre request script should preceed everything in the request, even the construction of the request itself, including body and headers etc. Otherwise the full potential of the pre request script is not there

frille700 avatar May 13 '24 18:05 frille700

@frille700 I get your point. But executing the pre-request script directly before the execution of the request has the advantage, that you can work with the fully prepared request. So maybe splitting the pre-request script in two (pre-prepare-request and pre-request) is better to get the best of both worlds.

marfranke avatar May 14 '24 09:05 marfranke

And it relates to https://github.com/usebruno/bruno/issues/2249. However, this issue describes the opposite...

marfranke avatar May 14 '24 09:05 marfranke

Yes I have realized the advantages with the pre request too. I got it to work by using the req.setBody in the pre request script and that way was able to set what I wanted. But, as you point out, it would be neat with a pre-prepare-request kind of thing

frille700 avatar May 14 '24 09:05 frille700

Similar issue with variables in the URL segment. E.g. {{serverRoot}/content/{{id}} After {{id}} change next request will use old {{id}} value and only 2nd attempt will use new value.

VeselovAndrey avatar May 15 '24 05:05 VeselovAndrey

I got it to work by using the req.setBody in the pre request script and that way was able to set what I wanted.

thanks @frille700 - this is a workaround I can work with

applepies avatar May 15 '24 08:05 applepies

Similar issue with variables in the URL segment. E.g. {{serverRoot}/content/{{id}} After {{id}} change next request will use old {{id}} value and only 2nd attempt will use new value.

This, in particular, has broken all my collections. Is the intention to remove that capability entirely? If not, how would you set those before the request now?

lewg avatar May 15 '24 13:05 lewg

@VeselovAndrey: I'm getting the same issue. Downgrading to version v1.14.0 appears to fix it.

fburato avatar May 15 '24 16:05 fburato

Similar issue with variables in the URL segment. E.g. {{serverRoot}/content/{{id}} After {{id}} change next request will use old {{id}} value and only 2nd attempt will use new value.

This, in particular, has broken all my collections. Is the intention to remove that capability entirely? If not, how would you set those before the request now?

This can be dangerous if you are doing operations in a production environment. Needs to be fixed or users warned.

luisdosreis avatar May 23 '24 11:05 luisdosreis

@applepies @frille700 @VeselovAndrey @lewg @fburato @marfranke @luisdosreis

This issue has been fixed in v1.18.0.

Could you please verify and let me know if you're still facing any issues?

lohxt1 avatar May 23 '24 12:05 lohxt1

@lohxt1 Did a quick test with 1 request and 2 different values in a URL segment - see no issues.

VeselovAndrey avatar May 27 '24 06:05 VeselovAndrey

Can confirm that it seems fixed in v1.18.0.

luisdosreis avatar May 27 '24 11:05 luisdosreis

closing

please re-open if you are still facing the issue

lohxt1 avatar Jun 14 '24 08:06 lohxt1