Re: Fix for recursive plpython triggers
Tom Lane <tgl@sss.pgh.pa.us>
From: Tom Lane <tgl@sss.pgh.pa.us>
To: Andreas Karlsson <andreas@proxel.se>
Cc: pgsql-hackers@lists.postgresql.org
Date: 2024-05-08T15:51:17Z
Lists: pgsql-hackers
Attachments
- fix-plpython-record-result-setup.patch (text/x-diff) patch
Andreas Karlsson <andreas@proxel.se> writes:
> I found this issue while reading the code, so am very unclear if there
> is any sane code which could trigger it.
> In the example below the recursive call to f('int') changes the return
> type of the f('text') call causing it to fail.
> # CREATE OR REPLACE FUNCTION f(t text) RETURNS record LANGUAGE
> plpython3u AS $$
> if t == "text":
> plpy.execute("SELECT * FROM f('int') AS (a int)");
> return { "a": "x" }
> elif t == "int":
> return { "a": 1 }
> $$;
> CREATE FUNCTION
> # SELECT * FROM f('text') AS (a text);
> ERROR: invalid input syntax for type integer: "x"
> CONTEXT: while creating return value
> PL/Python function "f"
Oh, nice one. I think we can fix this trivially though: the problem
is that RECORD return-type setup was stuck into PLy_function_build_args,
where it has no particular business being in the first place, rather
than being done at the point of use. We can just move the code.
regards, tom lane
Commits
-
Fix recursive RECORD-returning plpython functions.
- d727c543176c 17.0 landed
- d39337021e12 14.13 landed
- 6e29963edd55 15.8 landed
- 52ea653aa9d8 16.4 landed
- 2728677923d2 13.16 landed
- 157b1e6b41b4 12.20 landed
-
Don't corrupt plpython's "TD" dictionary in a recursive trigger call.
- c5bec5426af9 17.0 landed
- be18a12b6631 16.4 landed
- abe60b6a0d27 13.16 landed
- 90d39929a890 14.13 landed
- 4488142a463c 12.20 landed
- 363e8c2f98b8 15.8 landed