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

previous value of variable used in JSON body #2303

Open
2 tasks done
applepies opened this issue May 13, 2024 · 12 comments
Open
2 tasks done

previous value of variable used in JSON body #2303

applepies opened this issue May 13, 2024 · 12 comments
Assignees
Labels
bug Something isn't working

Comments

@applepies
Copy link

I have checked the following:

  • I use the newest version of bruno.
  • 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 applepies added the bug Something isn't working label May 13, 2024
@frille700
Copy link

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

@marfranke
Copy link

@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
Copy link

And it relates to #2249. However, this issue describes the opposite...

@frille700
Copy link

frille700 commented May 14, 2024

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

@VeselovAndrey
Copy link

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.

@applepies
Copy link
Author

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

@lewg
Copy link

lewg commented May 15, 2024

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?

@fburato
Copy link

fburato commented May 15, 2024

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

@luisdosreis
Copy link

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.

@lohxt1
Copy link
Collaborator

lohxt1 commented May 23, 2024

@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 lohxt1 self-assigned this May 23, 2024
@VeselovAndrey
Copy link

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

@luisdosreis
Copy link

Can confirm that it seems fixed in v1.18.0.

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

8 participants