Skip to content

fix: keep strict, parallel, cost and rows when updating a function definition - #1154

Open
breken-ai wants to merge 1 commit into
supabase:masterfrom
breken-ai:fix/function-update-keeps-attributes
Open

breken-ai wants to merge 1 commit into
supabase:masterfrom
breken-ai:fix/function-update-keeps-attributes

Conversation

@breken-ai

Copy link
Copy Markdown

What kind of change does this PR introduce?

Bug fix

What is the current behavior?

PATCH /functions/:id with a new definition re-creates the function with CREATE OR REPLACE FUNCTION (generateCreateFunctionSql). That SQL hard-codes CALLED ON NULL INPUT. It also never writes out PARALLEL, COST or ROWS.

CREATE OR REPLACE resets every attribute that it doesn't spell out to its default. So editing only the body of this function:

create function public.f(a int) returns setof int
  language sql immutable strict parallel safe cost 5 rows 3
  as 'select a + 1';

silently changes it. Here is what pg_proc shows before and after the edit:

before after update(id, { definition }) on master
proisstrict true false
proparallel s u
procost 5 100
prorows 3 1000

Losing STRICT changes what the function returns: a null argument now runs the body instead of returning null. Losing PARALLEL SAFE makes every query that calls the function run without parallel plans.

What is the new behavior?

When definition is updated, update() reads proisstrict, proparallel, procost, prorows and proretset from pg_proc for the function. It passes them to generateCreateFunctionSql, which then emits STRICT or CALLED ON NULL INPUT, PARALLEL …, COST …, and, for set-returning functions only, ROWS …. The create path is unchanged.

Additional context

I added the test update definition keeps strictness, parallel safety, cost and rows to test/lib/functions.ts.

  • On master it fails and reports the reset values from the table above.
  • With the fix, test/index.test.ts passes 148/148 against the test/db image (supabase/postgres:14.1.0).
  • npm run check and prettier -c are clean.

LEAKPROOF is left out on purpose. Only superusers can set it, so carrying it over would make definition updates fail for non-superuser owners.

This PR was prepared with an AI coding assistant (Claude Code). I reproduced the failure and ran the tests against a real Postgres.

🤖 Generated with Claude Code

…finition

The definition update re-creates the function with CREATE OR REPLACE and a
hard-coded CALLED ON NULL INPUT. Attributes that are not spelled out reset to
their defaults, so editing the body of a STRICT PARALLEL SAFE function made
it non-strict and PARALLEL UNSAFE, and reset COST and ROWS.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
@breken-ai
breken-ai requested review from a team, avallete and soedirgo as code owners September 26, 2026 04:00

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

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant