Исходный код СУБД RuDB — свободной СУБД с открытым исходным кодом на базе PostgreSQL
rudb
2 days ago bd039d1e92813358c5c5a1e346b49074baf513f2
src/pl/plpython/sql/plpython_spi.sql
@@ -307,3 +307,42 @@
SELECT cursor_plan();
SELECT cursor_plan_wrong_args();
SELECT plan_composite_args();
-- A custom argument sequence whose length matches the plan but whose
-- __getitem__ raises should be reported as an error, not crash the backend.
CREATE FUNCTION plan_broken_arg_sequence() RETURNS void AS $$
plan = plpy.prepare("select $1", ["int4"])
class C:
    def __len__(self):
        return 1
    def __getitem__(self, i):
        raise ValueError('getitem failed')
plpy.execute(plan, C())
$$ LANGUAGE plpython3u;
SELECT plan_broken_arg_sequence();
-- Likewise for the type-name list passed to plpy.prepare().
CREATE FUNCTION prepare_broken_type_sequence() RETURNS void AS $$
class C:
    def __len__(self):
        return 1
    def __getitem__(self, i):
        raise ValueError('getitem failed')
plpy.prepare("select $1", C())
$$ LANGUAGE plpython3u;
SELECT prepare_broken_type_sequence();
-- Likewise for the argument sequence passed to plpy.cursor().
CREATE FUNCTION cursor_broken_arg_sequence() RETURNS void AS $$
plan = plpy.prepare("select $1", ["int4"])
class C:
    def __len__(self):
        return 1
    def __getitem__(self, i):
        raise ValueError('getitem failed')
plpy.cursor(plan, C())
$$ LANGUAGE plpython3u;
SELECT cursor_broken_arg_sequence();