fix(sanity-best-practices): use configured dataset in functions example#63
Merged
jonahsnider merged 1 commit intoJul 22, 2026
Conversation
jonahsnider
self-requested a review
July 22, 2026 16:47
jonahsnider
approved these changes
Jul 22, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
Summary
Updates the Sanity Functions documentation example for "Recursion control with custom HTTP clients" to use the active dataset from
context.clientOptions.datasetinstead of hardcodingproduction.Problem
The current example uses:
/data/mutate/productionThat makes the example incorrect for any project using a non-
productiondataset. If copied as-is, the request can target the wrong dataset or fail unexpectedly.Fix
Replace the hardcoded dataset with:
/data/mutate/${context.clientOptions.dataset}This keeps the example aligned with the function runtime context and makes it work across environments.
Testing
Docs-only change.
Verified the example now references the active dataset from function context instead of a hardcoded dataset.
Bug Report
If you find a security vulnerability, do NOT open an issue. Email security@sanity.io instead.
Describe the bug
The Sanity Functions example for "Recursion control with custom HTTP clients" hardcodes the dataset to
productionin the mutation URL. In non-productiondatasets, copying this example sends mutations to the wrong dataset.To Reproduce
Steps to reproduce the behavior:
/data/mutate/production.staging.productioninstead of the active dataset.Expected behavior
The example should use
context.clientOptions.dataset, for example:/data/mutate/${context.clientOptions.dataset}Screenshots
N/A
Which versions of Sanity are you using?
I could not capture a verbatim
sanity versionsoutput in this environment because the CLI attempted a network lookup, but the local workspace is using:sanity:5.31.1@sanity/functions:1.4.0@sanity/blueprints:0.15.2@sanity/client:7.24.0@sanity/cli:4.19.0What operating system are you using?
macOS 26.5.2 (Build 25F84) on Apple Silicon
Which versions of Node.js / npm are you running?
10.9.2v22.15.0Additional context
The current example uses:
https://${context.clientOptions.projectId}.api.sanity.io/v2025-05-08/data/mutate/productionIt should use the dataset from
context.clientOptions.datasetso the example works correctly across environments.Security issue?
No. This is a documentation/example bug, not a security issue.