Skip to content

fix: apply specific environment when sending requests in the template - #8780

Merged
ZxBing0066 merged 4 commits into
developfrom
fix/template-render-error-when-a-dep-request-uses-environment
Jun 6, 2025
Merged

fix: apply specific environment when sending requests in the template#8780
ZxBing0066 merged 4 commits into
developfrom
fix/template-render-error-when-a-dep-request-uses-environment

Conversation

@ZxBing0066

Copy link
Copy Markdown
Member

Background

INS-5180
When running tests via the Inso CLI, users need to specify the environment. The request sent from the test via insomnia.send respects the specific environment, but the request sent from the template doesn't. Which leads to the environment render error.

Changes

  • Unify fetchInsoRequestData and fetchRequestData to avoid inconsistent issues
  • Pass environmentId when sending requests in the template

@ZxBing0066 ZxBing0066 self-assigned this Jun 4, 2025
@ZxBing0066
ZxBing0066 marked this pull request as ready for review June 4, 2025 09:30
@ZxBing0066
ZxBing0066 requested a review from Copilot June 4, 2025 09:30

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR resolves an environment rendering error by ensuring that the proper environment is applied when sending requests from templates. Key changes include unifying the request data fetching functions, adding an optional environmentId parameter to the network request calls, and updating related type definitions and tests.

Reviewed Changes

Copilot reviewed 10 out of 10 changed files in this pull request and generated 1 comment.

Show a summary per file
File Description
packages/insomnia/src/ui/components/templating/local-template-tags.ts Passes environmentId when sending requests from templates to fix environment render errors.
packages/insomnia/src/templating/types.ts Updates type definitions for sendRequest to include an optional environmentId.
packages/insomnia/src/plugins/context/network.ts Updates the sendRequest method to forward the environmentId parameter.
packages/insomnia/src/network/network.ts Modifies fetchRequestData to utilize the overrideEnvironmentId parameter and adjust the returned activeEnvironmentId.
packages/insomnia/src/common/send-request.ts Refactors to use fetchRequestData instead of the outdated fetchInsoRequestData.
packages/insomnia-inso/* Minor updates and additions to tests and fixtures ensuring consistency with the environment changes.
Comments suppressed due to low confidence (2)

packages/insomnia/src/ui/components/templating/local-template-tags.ts:668

  • Ensure that the variable 'environmentId' is defined in this scope before being used in the sendRequest call (it is referenced on lines 670-672) to avoid potential runtime errors.
response = await context.network.sendRequest(request, { requestChain });

packages/insomnia/src/network/network.ts:227

  • Consider returning the calculated activeEnvironmentId (derived from overrideEnvironmentId or workspaceMeta) instead of always using environment._id to preserve the intended override behavior.
activeEnvironmentId: environment._id,

Comment thread packages/insomnia/src/plugins/context/network.ts
@ZxBing0066
ZxBing0066 requested review from a team, cwangsmv, ihexxa and jackkav June 4, 2025 09:31

@jackkav jackkav left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I worry a bit about creating a new way to set an environmentId, as I feel there might be another but I could be wrong. Nice job cutting down the fetchRequestData drift.

@ZxBing0066

Copy link
Copy Markdown
Member Author

I worry a bit about creating a new way to set an environmentId, as I feel there might be another but I could be wrong.

Yeah, good point. I think maybe we can set the environmentId into the workspace and override the one in the workspace meta in the database, then we don't need to carry the environmentId across the entire process. Not sure about the effort and risk, maybe we can consider it when we meet another related issue/requirement.

@ZxBing0066
ZxBing0066 enabled auto-merge (squash) June 6, 2025 09:37
@ZxBing0066
ZxBing0066 merged commit 14ce962 into develop Jun 6, 2025
@ZxBing0066
ZxBing0066 deleted the fix/template-render-error-when-a-dep-request-uses-environment branch June 6, 2025 09:50
RoamingLost pushed a commit to RoamingLost/insomnia that referenced this pull request Aug 6, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants