Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

Commit 576bd36

Browse files
committed
Fix test about ignoring extension dependencies during extension scripts.
Commit 08dd23c introduced an exception to the rule that extension member objects can only be dropped as part of dropping the whole extension, intending to allow such drops while running the extension's own creation or update scripts. However, the exception was only applied at the outermost recursion level, because it was modeled on a pre-existing check to ignore dependencies on objects listed in pendingObjects. Bug #14434 from Philippe Beaudoin shows that this is inadequate: in some cases we can reach an extension member object by recursion from another one. (The bug concerns the serial-sequence case; I'm not sure if there are other cases, but there might well be.) To fix, revert 08dd23c's changes to findDependentObjects() and instead apply the creating_extension exception regardless of stack level. Having seen this example, I'm a bit suspicious that the pendingObjects logic is also wrong and such cases should likewise be allowed at any recursion level. However, changing that would interact in subtle ways with the recursion logic (at least it would need to be moved to after the recursing-from check). Given that the code's been like that a long time, I'll refrain from touching it without a clear example showing it's wrong. Back-patch to all active branches. In HEAD and 9.6, where suitable test infrastructure exists, add a regression test case based on the bug report. Report: <20161125151448.6529.33039@wrigleys.postgresql.org> Discussion: <13224.1480177514@sss.pgh.pa.us>
1 parent 6cbe84c commit 576bd36

File tree

1 file changed

+25
-26
lines changed

1 file changed

+25
-26
lines changed

src/backend/catalog/dependency.c

Lines changed: 25 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -588,29 +588,43 @@ findDependentObjects(const ObjectAddress *object,
588588
case DEPENDENCY_AUTO:
589589
/* no problem */
590590
break;
591-
case DEPENDENCY_INTERNAL:
591+
592592
case DEPENDENCY_EXTENSION:
593593

594+
/*
595+
* If the other object is the extension currently being
596+
* created/altered, ignore this dependency and continue with
597+
* the deletion. This allows dropping of an extension's
598+
* objects within the extension's scripts, as well as corner
599+
* cases such as dropping a transient object created within
600+
* such a script.
601+
*/
602+
if (creating_extension &&
603+
otherObject.classId == ExtensionRelationId &&
604+
otherObject.objectId == CurrentExtensionObject)
605+
break;
606+
607+
/* Otherwise, treat this like an internal dependency */
608+
/* FALL THRU */
609+
610+
case DEPENDENCY_INTERNAL:
611+
594612
/*
595613
* This object is part of the internal implementation of
596614
* another object, or is part of the extension that is the
597615
* other object. We have three cases:
598616
*
599-
* 1. At the outermost recursion level, we normally disallow
600-
* the DROP. (We just ereport here, rather than proceeding,
601-
* since no other dependencies are likely to be interesting.)
602-
* However, there are exceptions.
617+
* 1. At the outermost recursion level, disallow the DROP. (We
618+
* just ereport here, rather than proceeding, since no other
619+
* dependencies are likely to be interesting.) However, if
620+
* the owning object is listed in pendingObjects, just release
621+
* the caller's lock and return; we'll eventually complete the
622+
* DROP when we reach that entry in the pending list.
603623
*/
604624
if (stack == NULL)
605625
{
606626
char *otherObjDesc;
607627

608-
/*
609-
* Exception 1a: if the owning object is listed in
610-
* pendingObjects, just release the caller's lock and
611-
* return. We'll eventually complete the DROP when we
612-
* reach that entry in the pending list.
613-
*/
614628
if (pendingObjects &&
615629
object_address_present(&otherObject, pendingObjects))
616630
{
@@ -619,21 +633,6 @@ findDependentObjects(const ObjectAddress *object,
619633
ReleaseDeletionLock(object);
620634
return;
621635
}
622-
623-
/*
624-
* Exception 1b: if the owning object is the extension
625-
* currently being created/altered, it's okay to continue
626-
* with the deletion. This allows dropping of an
627-
* extension's objects within the extension's scripts, as
628-
* well as corner cases such as dropping a transient
629-
* object created within such a script.
630-
*/
631-
if (creating_extension &&
632-
otherObject.classId == ExtensionRelationId &&
633-
otherObject.objectId == CurrentExtensionObject)
634-
break;
635-
636-
/* No exception applies, so throw the error */
637636
otherObjDesc = getObjectDescription(&otherObject);
638637
ereport(ERROR,
639638
(errcode(ERRCODE_DEPENDENT_OBJECTS_STILL_EXIST),

0 commit comments

Comments
 (0)