Ticket #3 (closed defect: fixed)

Opened 3 years ago

Last modified 3 years ago

Remove IMMUTABLE from `test.assert_rows()`

Reported by: guest Owned by: fumanchu
Priority: major Milestone: 1.0
Component: assertions Keywords:
Cc:

Description

Following our email exchange, here is another bug that came up when I tried to use global:

    CREATE TYPE foo AS ( id int, name text );

    CREATE OR REPLACE FUNCTION public.fooies()
     RETURNS SETOF foo LANGUAGE sql
     AS $$ VALUES (42, 'Fred'::text), (99, 'Bob'::text); $$;

    CREATE OR REPLACE FUNCTION test.test_fooies() RETURNS VOID AS $_$
    BEGIN
        PREPARE want AS VALUES(42, 'BET'), (99, 'Bob');
        PERFORM test.assert_rows(
            test.global($$ EXECUTE want $$),
            test.global($$ SELECT * FROM public.fooies() $$)
        );
        RAISE EXCEPTION '[OK]';
    END;
    $_$ LANGUAGE plpgsql;

    SELECT * FROM test.test_fooies();

This unexpectedly passes on 8.4beta2. The problem is that assert_rows() is marked IMMUTABLE. Of course, it's not immutable, as we're fetching data from tables (which is rather the point of globa(). The fix:

Index: epic.sql
===================================================================
--- epic.sql	(revision 28)
+++ epic.sql	(working copy)
@@ -723,7 +723,7 @@
     RAISE EXCEPTION 'Record: % from: % not found in: %', rec, call_2, call_1;
   END LOOP;
 END;
-$$ LANGUAGE plpgsql IMMUTABLE;
+$$ LANGUAGE plpgsql;
 
 
 CREATE OR REPLACE FUNCTION test.assert_column(call text, expected anyarray, colname text) RETURNS VOID AS $$

—Theory

Change History

Changed 3 years ago by guest

FYI, you'll need to apply the patch in #4 to get the above example to work, as it uses VALUES. :-)

—Theory

Changed 3 years ago by fumanchu

  • status changed from new to accepted
  • milestone set to 1.0

Changed 3 years ago by fumanchu

  • status changed from accepted to closed
  • resolution set to fixed

Fixed in [29].

Note: See TracTickets for help on using tickets.