]> granicus.if.org Git - postgresql/commitdiff
Fix AfterTriggerSaveEvent to use a test and elog, not just Assert, to check
authorTom Lane <tgl@sss.pgh.pa.us>
Tue, 27 Oct 2009 20:14:33 +0000 (20:14 +0000)
committerTom Lane <tgl@sss.pgh.pa.us>
Tue, 27 Oct 2009 20:14:33 +0000 (20:14 +0000)
that it's called within an AfterTriggerBeginQuery/AfterTriggerEndQuery pair.
The RI cascade triggers suppress that overhead on the assumption that they
are always run non-deferred, so it's possible to violate the condition if
someone mistakenly changes pg_trigger to mark such a trigger deferred.
We don't really care about supporting that, but throwing an error instead
of crashing seems desirable.  Per report from Marcelo Costa.

src/backend/commands/trigger.c

index bb628ed80a3a9b1edbb5c1233a02cf178820ee49..2505de062305a232e025b7b71ae4f25c27c82499 100644 (file)
@@ -7,7 +7,7 @@
  * Portions Copyright (c) 1994, Regents of the University of California
  *
  * IDENTIFICATION
- *       $PostgreSQL: pgsql/src/backend/commands/trigger.c,v 1.248 2009/06/18 01:27:02 tgl Exp $
+ *       $PostgreSQL: pgsql/src/backend/commands/trigger.c,v 1.248.2.1 2009/10/27 20:14:33 tgl Exp $
  *
  *-------------------------------------------------------------------------
  */
@@ -3800,9 +3800,15 @@ AfterTriggerSaveEvent(ResultRelInfo *relinfo, int event, bool row_trigger,
        int                     ntriggers;
        int                *tgindx;
 
+       /*
+        * Check state.  We use normal tests not Asserts because it is possible
+        * to reach here in the wrong state given misconfigured RI triggers,
+        * in particular deferring a cascade action trigger.
+        */
        if (afterTriggers == NULL)
                elog(ERROR, "AfterTriggerSaveEvent() called outside of transaction");
-       Assert(afterTriggers->query_depth >= 0);
+       if (afterTriggers->query_depth < 0)
+               elog(ERROR, "AfterTriggerSaveEvent() called outside of query");
 
        /*
         * Validate the event code and collect the associated tuple CTIDs.