Skip to content

docs: note SELECT RLS needed for INSERT RETURNING via Data API - #48308

Open
rohanpatel2002 wants to merge 1 commit into
supabase:masterfrom
rohanpatel2002:docs/rls-insert-returning-select
Open

rohanpatel2002 wants to merge 1 commit into
supabase:masterfrom
rohanpatel2002:docs/rls-insert-returning-select

Conversation

@rohanpatel2002

@rohanpatel2002 rohanpatel2002 commented Jul 24, 2026 •

Copy link
Copy Markdown

I have read the CONTRIBUTING.md file.

YES

What kind of change does this PR introduce?

Docs update

What is the current behavior?

The RLS guide warns that UPDATE needs a matching SELECT policy, but the INSERT section does not mention that Data API inserts which return the row (Prefer: return=representation / supabase-js .insert(...).select()) run INSERT … RETURNING * and also need SELECT RLS.

That leads to reports like #48302 (same pattern as #43528 / #47917): INSERT policy + GRANT look correct, SET ROLE anon; INSERT works in the SQL Editor, but REST still returns 42501.

What is the new behavior?

Under INSERT policies, the guide now cautions that:

  • Returning the inserted row requires a corresponding SELECT policy
  • An INSERT-only policy is enough for plain SQL without RETURNING
  • Workarounds: omit .select(), use Prefer: returninimal, or add a SELECT policy (example included)

Additional context

No product code changes. Aligns INSERT docs with the existing UPDATE SELECT warning and with Storage’s INSERT+RETURNING troubleshooting note.

Clarify why INSERT policies can pass in SQL but fail over PostgREST
when the client requests the inserted row back.
Related to supabase#48302
@rohanpatel2002
rohanpatel2002 requested a review from a team as a code owner July 24, 2026 16:01
@github-actions

Copy link
Copy Markdown
Contributor

Thanks for contributing to Supabase! ❤️ Our team will review your PR.

A few tips for a smoother review process:

  • If you have a local version of the repo, run pnpm run format to make sure formatting checks pass.
  • Once we've reviewed your PR, please don't trivially merge master (don't click Update branch if there are no merge conflicts to be fixed). This invalidates any pre-merge checks we've run.

@github-actions github-actions Bot added the documentation Improvements or additions to documentation label Jul 24, 2026
@vercel

vercel Bot commented Jul 24, 2026 •

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
design-system Error Error Jul 24, 2026 4:04pm

Request Review

@vercel

vercel Bot commented Jul 24, 2026

Copy link
Copy Markdown

@rohanpatel2002 is attempting to deploy a commit to the Supabase Team on Vercel.

A member of the Team first needs to authorize it.

@coderabbitai

coderabbitai Bot commented Jul 24, 2026 •

Copy link
Copy Markdown
Contributor

Review Change Stack

Caution

Review failed

Failed to post review comments.

We encountered an issue with GitHub. Use @coderabbitai full review to retry the review.

⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro Plus

Run ID: 37a05002-47c1-4ebe-a8e0-d1c60eda6c40

📥 Commits

Reviewing files that changed from the base of the PR and between 8d4d3b5 and e498609.

📒 Files selected for processing (1)
  • apps/docs/content/guides/database/postgres/row-level-security.mdx
⚠️ CI failures not shown inline (7)

Commit Status: Vercel – ui-library: Vercel – ui-library

Conclusion: failure

Authorization required to deploy.

Commit Status: Vercel – studio-staging: Vercel – studio-staging

Conclusion: failure

Authorization required to deploy.

Commit Status: Vercel – zone-www-dot-com: Vercel – zone-www-dot-com

Conclusion: failure

Authorization required to deploy.

Commit Status: Vercel – studio-self-hosted: Vercel – studio-self-hosted

Conclusion: failure

Authorization required to deploy.

Commit Status: Vercel – docs: Vercel – docs

Conclusion: failure

Authorization required to deploy.

Commit Status: Vercel – studio: Vercel – studio

Conclusion: failure

Authorization required to deploy.

Commit Status: Vercel – design-system: Vercel – design-system

Conclusion: failure

Deployment has failed — run this Vercel CLI command: npx vercel inspect dpl_J6LxVvasuD8ufzaf34TXUBm7bGy4 --logs
🧰 Additional context used
🧠 Learnings (3)
📚 Learning: 2026-01-05T23:42:52.357Z
Learnt from: kallebysantos
Repo: supabase/supabase PR: 41727
File: apps/docs/content/guides/functions/auth.mdx:93-93
Timestamp: 2026-01-05T23:42:52.357Z
Learning: When reviewing MDX documentation that uses CodeSample components in Supabase docs, it's acceptable for CodeSample meta attributes to display generic example file names (e.g., hello/index.ts) to illustrate templating. Do not flag these as file-path mismatches unless the docs claim an exact reference to a real file. If you encounter such code samples, ensure the surrounding text clarifies that the names are placeholders to be adapted by users, and suggest adding a note explaining how to map the template to a real project path.

Applied to files:

  • apps/docs/content/guides/database/postgres/row-level-security.mdx
📚 Learning: 2026-05-19T00:35:54.333Z
Learnt from: aidankmcalister
Repo: supabase/supabase PR: 46082
File: apps/docs/content/guides/database/prisma.mdx:417-421
Timestamp: 2026-05-19T00:35:54.333Z
Learning: In Supabase docs (.mdx) that show code examples runnable across multiple runtimes (e.g., npm/pnpm/yarn/bun), treat missing dotenv initialization as a Node.js-specific issue when the example uses `process.env`. Bun auto-loads `.env` (so `process.env` is available without `dotenv/config`), but Node.js does not—require an explicit `import "dotenv/config"` (or an equivalent `dotenv.config()` call) for Node-targeted execution paths/snippets. Even if the author tested with Bun, reviewers should still flag missing dotenv when the docs claim Node compatibility.

Applied to files:

  • apps/docs/content/guides/database/postgres/row-level-security.mdx
📚 Learning: 2026-07-15T13:42:14.515Z
Learnt from: mandarini
Repo: supabase/supabase PR: 47966
File: apps/docs/content/guides/auth/choosing-a-server-package.mdx:65-65
Timestamp: 2026-07-15T13:42:14.515Z
Learning: When documenting environment variables for the `supabase/server` “named-keys” model, describe and prefer the plural JSON key-map variables `SUPABASE_PUBLISHABLE_KEYS` and `SUPABASE_SECRET_KEYS` (resolved via `resolveEnv`). Mention that singular `SUPABASE_PUBLISHABLE_KEY` / `SUPABASE_SECRET_KEY` are supported only as a single-key fallback. Avoid presenting `SUPABASE_ANON_KEY` / `SUPABASE_SERVICE_ROLE_KEY` as keys used by `supabase/server` (treat them as legacy/unused for this package).

Applied to files:

  • apps/docs/content/guides/database/postgres/row-level-security.mdx
📝 Walkthrough

Walkthrough

The PostgreSQL row-level security guide now explains that Data API inserts returning rows require both INSERT and SELECT policies, while plain SQL inserts without RETURNING can use an INSERT-only policy.

Changes

Row-level security INSERT guidance

Layer / File(s) Summary
Document row-returning INSERT requirements
apps/docs/content/guides/database/postgres/row-level-security.mdx
Adds a caution explaining INSERT ... RETURNING * behavior, when an INSERT-only policy is sufficient, and how to add a matching SELECT policy.

Estimated code review effort: 1 (Trivial) | ~3 minutes

Suggested reviewers: alaister

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Description check ⚠️ Warning The description omits the template's required YES/NO, change type, current behavior, new behavior, and additional context sections. Rewrite the PR description to follow the template and add each required section, including the CONTRIBUTING acknowledgement, change type, current/new behavior, and context.
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly matches the doc update about needing SELECT RLS for INSERT RETURNING via the Data API.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@coderabbitai coderabbitai Bot 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.

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@apps/docs/content/guides/database/postgres/row-level-security.mdx`:
- Around line 229-237: Update the SQL Editor example near the profiles
INSERT/RETURNING explanation so its execution context matches the
`authenticated` role targeted by the insert policy. Replace the `set role anon`
context or revise the example policy accordingly, ensuring the plain INSERT can
actually pass the INSERT policy before demonstrating the separate
`RETURNING`/SELECT requirement.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro Plus

Run ID: 37a05002-47c1-4ebe-a8e0-d1c60eda6c40

📥 Commits

Reviewing files that changed from the base of the PR and between 8d4d3b5 and e498609.

📒 Files selected for processing (1)
  • apps/docs/content/guides/database/postgres/row-level-security.mdx

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

documentation Improvements or additions to documentation

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant