Исходный код СУБД RuDB — свободной СУБД с открытым исходным кодом на базе PostgreSQL
rudb
3 days ago bd039d1e92813358c5c5a1e346b49074baf513f2
src/pl/plpython/expected/plpython_composite.out
@@ -606,3 +606,19 @@
HINT:  To return a composite type in an array, return the composite type as a Python tuple, e.g., "[('foo',)]".
CONTEXT:  while creating return value
PL/Python function "composite_type_as_list_broken"
-- A custom sequence whose length matches the tuple but whose __getitem__
-- raises should be reported as an error, not crash the backend.
CREATE FUNCTION composite_type_as_broken_sequence() RETURNS type_record AS $$
class C:
    def __len__(self):
        return 2
    def __getitem__(self, i):
        raise ValueError('getitem failed')
return C()
$$ LANGUAGE plpython3u;
SELECT * FROM composite_type_as_broken_sequence();
ERROR:  could not get element 0 from sequence
DETAIL:  ValueError: getitem failed
CONTEXT:  Traceback (most recent call last):
while creating return value
PL/Python function "composite_type_as_broken_sequence"