phacility/phabricator · error · Exception
Trying to activate a resource which has not yet been persist
Error message
Trying to activate a resource which has not yet been persisted.
What it means
DrydockResource::activateResource() refuses to activate a resource that has no database ID, i.e. one that was never saved. The activation flow (slot locks, status transition, didActivate) only works on a persisted row. This almost always means a blueprint created a resource template but never called allocateResource(), which is the step that persists it.
Source
Thrown at src/applications/drydock/storage/DrydockResource.php:190
$this->saveTransaction();
$this->isAllocated = true;
if ($new_status == DrydockResourceStatus::STATUS_ACTIVE) {
$this->didActivate();
}
return $this;
}
public function isAllocatedResource() {
return $this->isAllocated;
}
public function activateResource() {
if (!$this->getID()) {
throw new Exception(
pht(
'Trying to activate a resource which has not yet been persisted.'));
}
$expect_status = DrydockResourceStatus::STATUS_PENDING;
$actual_status = $this->getStatus();
if ($actual_status != $expect_status) {
throw new Exception(
pht(
'Trying to activate a resource from the wrong status. Status must '.
'be "%s", actually "%s".',
$expect_status,
$actual_status));
}
$this->openTransaction();
try {View on GitHub (pinned to 5720a38cfe)
Solutions
- Call $resource->allocateResource() (which acquires slot locks and saves the row with status pending or active) before calling activateResource().
- Create resources through $this->newResourceTemplate($blueprint) inside blueprint allocateResource() so the PHID/defaults are pregenerated.
- If activating an existing resource, reload it with DrydockResourceQuery so it has an ID instead of using a fresh in-memory object.
Example fix
// before $resource = $this->newResourceTemplate($blueprint); $resource->activateResource(); // throws: not persisted // after $resource = $this->newResourceTemplate($blueprint); $resource->allocateResource(); // persists (status pending) return $resource; // worker later calls activateResource()
Defensive patterns
Strategy: validation
Validate before calling
if (!$resource->getID()) {
throw new Exception(
pht('Resource is not persisted; call allocateResource() first.'));
}
$resource->activateResource(); Prevention
- Always create Drydock resources via newResourceTemplate() and persist them with allocateResource() before any activation step.
- Treat an object with no ID as a template, never as a live resource.
When it happens
Trigger: Calling activateResource() on a resource returned by DrydockBlueprintImplementation::newResourceTemplate() without first calling $resource->allocateResource(); custom code that constructs a DrydockResource in memory (setStatus + setPHID) and tries to activate it before save().
Common situations: Writing a custom Drydock blueprint and skipping the allocateResource() call inside allocateResource(); copying an example that pre-dates the allocate/activate split; activating a resource twice across code paths where the first call never persisted it.
Related errors
- Trying to activate a resource from the wrong status. Status
- Blueprint "%s" (of type "%s") is not properly implemented: %
- Trying to activate lease ("%s") on a resource ("%s") in the
- Blueprint "%s" (of type "%s") is not properly implemented: %
- Blueprint "%s" (of type "%s") is not properly implemented: i
AI-assisted analysis of phacility/phabricator@5720a38cfe (2026-08-21).
Data as JSON: /api/errors/86af00d02c96b104.
Report an issue: GitHub.