Skip to content

Commit 44956c5

Browse files
committed
Fix AfterTriggerSaveEvent to use a test and elog, not just Assert, to check
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.
1 parent 61e5328 commit 44956c5

File tree

1 file changed

+8
-2
lines changed

1 file changed

+8
-2
lines changed

src/backend/commands/trigger.c

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
* Portions Copyright (c) 1994, Regents of the University of California
88
*
99
* IDENTIFICATION
10-
* $PostgreSQL: pgsql/src/backend/commands/trigger.c,v 1.255 2009/10/26 02:26:28 tgl Exp $
10+
* $PostgreSQL: pgsql/src/backend/commands/trigger.c,v 1.256 2009/10/27 20:14:27 tgl Exp $
1111
*
1212
*-------------------------------------------------------------------------
1313
*/
@@ -3895,9 +3895,15 @@ AfterTriggerSaveEvent(ResultRelInfo *relinfo, int event, bool row_trigger,
38953895
int ntriggers;
38963896
int *tgindx;
38973897

3898+
/*
3899+
* Check state. We use normal tests not Asserts because it is possible
3900+
* to reach here in the wrong state given misconfigured RI triggers,
3901+
* in particular deferring a cascade action trigger.
3902+
*/
38983903
if (afterTriggers == NULL)
38993904
elog(ERROR, "AfterTriggerSaveEvent() called outside of transaction");
3900-
Assert(afterTriggers->query_depth >= 0);
3905+
if (afterTriggers->query_depth < 0)
3906+
elog(ERROR, "AfterTriggerSaveEvent() called outside of query");
39013907

39023908
/*
39033909
* Validate the event code and collect the associated tuple CTIDs.

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy