Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 2cbb62d

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: <[email protected]> Discussion: <[email protected]>
1 parent 05bef7b commit 2cbb62d

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
@@ -574,29 +574,43 @@ findDependentObjects(const ObjectAddress *object,
574574
case DEPENDENCY_AUTO:
575575
/* no problem */
576576
break;
577-
case DEPENDENCY_INTERNAL:
577+
578578
case DEPENDENCY_EXTENSION:
579579

580+
/*
581+
* If the other object is the extension currently being
582+
* created/altered, ignore this dependency and continue with
583+
* the deletion. This allows dropping of an extension's
584+
* objects within the extension's scripts, as well as corner
585+
* cases such as dropping a transient object created within
586+
* such a script.
587+
*/
588+
if (creating_extension &&
589+
otherObject.classId == ExtensionRelationId &&
590+
otherObject.objectId == CurrentExtensionObject)
591+
break;
592+
593+
/* Otherwise, treat this like an internal dependency */
594+
/* FALL THRU */
595+
596+
case DEPENDENCY_INTERNAL:
597+
580598
/*
581599
* This object is part of the internal implementation of
582600
* another object, or is part of the extension that is the
583601
* other object. We have three cases:
584602
*
585-
* 1. At the outermost recursion level, we normally disallow
586-
* the DROP. (We just ereport here, rather than proceeding,
587-
* since no other dependencies are likely to be interesting.)
588-
* However, there are exceptions.
603+
* 1. At the outermost recursion level, disallow the DROP. (We
604+
* just ereport here, rather than proceeding, since no other
605+
* dependencies are likely to be interesting.) However, if
606+
* the owning object is listed in pendingObjects, just release
607+
* the caller's lock and return; we'll eventually complete the
608+
* DROP when we reach that entry in the pending list.
589609
*/
590610
if (stack == NULL)
591611
{
592612
char *otherObjDesc;
593613

594-
/*
595-
* Exception 1a: if the owning object is listed in
596-
* pendingObjects, just release the caller's lock and
597-
* return. We'll eventually complete the DROP when we
598-
* reach that entry in the pending list.
599-
*/
600614
if (pendingObjects &&
601615
object_address_present(&otherObject, pendingObjects))
602616
{
@@ -605,21 +619,6 @@ findDependentObjects(const ObjectAddress *object,
605619
ReleaseDeletionLock(object);
606620
return;
607621
}
608-
609-
/*
610-
* Exception 1b: if the owning object is the extension
611-
* currently being created/altered, it's okay to continue
612-
* with the deletion. This allows dropping of an
613-
* extension's objects within the extension's scripts, as
614-
* well as corner cases such as dropping a transient
615-
* object created within such a script.
616-
*/
617-
if (creating_extension &&
618-
otherObject.classId == ExtensionRelationId &&
619-
otherObject.objectId == CurrentExtensionObject)
620-
break;
621-
622-
/* No exception applies, so throw the error */
623622
otherObjDesc = getObjectDescription(&otherObject);
624623
ereport(ERROR,
625624
(errcode(ERRCODE_DEPENDENT_OBJECTS_STILL_EXIST),

0 commit comments

Comments
 (0)