phacility/phabricator · error · Exception
Trying to allocate a resource with no generated PHID. Use "%
Error message
Trying to allocate a resource with no generated PHID. Use "%s" to create new resource templates.
What it means
Drydock resources must be created through DrydockBlueprintImplementation::newResourceTemplate(), which builds the object, generates its PHID, and sets status PENDING. allocateResource() then persists it and runs the allocation lifecycle. If allocateResource() is called on a resource object lacking a PHID (i.e. constructed directly via new DrydockResource() or saved without a PHID), the allocator refuses: persisted Drydock objects are keyed by PHID and the allocation bookkeeping depends on it. This is a pure programmer error in blueprint implementation code.
Source
Thrown at src/applications/drydock/storage/DrydockResource.php:121
return false;
}
public function setActivateWhenAllocated($activate) {
$this->activateWhenAllocated = $activate;
return $this;
}
public function needSlotLock($key) {
$this->slotLocks[] = $key;
return $this;
}
public function allocateResource() {
// We expect resources to have a pregenerated PHID, as they should have
// been created by a call to DrydockBlueprint->newResourceTemplate().
if (!$this->getPHID()) {
throw new Exception(
pht(
'Trying to allocate a resource with no generated PHID. Use "%s" to '.
'create new resource templates.',
'newResourceTemplate()'));
}
$expect_status = DrydockResourceStatus::STATUS_PENDING;
$actual_status = $this->getStatus();
if ($actual_status != $expect_status) {
throw new Exception(
pht(
'Trying to allocate a resource from the wrong status. Status must '.
'be "%s", actually "%s".',
$expect_status,
$actual_status));
}
if ($this->activateWhenAllocated) {View on GitHub (pinned to 5720a38cfe)
Solutions
- Create resources via the template API inside your implementation: `$resource = $this->newResourceTemplate($blueprint);` then configure and `$resource->allocateResource()`
- Never call `new DrydockResource()` directly in allocation paths — the constructor does not generate a PHID
- If porting old blueprint code from an earlier Drydock version, update to the newResourceTemplate() pattern introduced with the rewritten allocator
- Check that you are not re-using an already-saved resource object for a second allocation
Example fix
// before $resource = new DrydockResource(); $resource->setBlueprintPHID($blueprint->getPHID()); $resource->allocateResource(); // Exception: Trying to allocate a resource with no generated PHID... // after $resource = $this->newResourceTemplate($blueprint); $resource->allocateResource();
Defensive patterns
Strategy: validation
Validate before calling
// Assert the template is properly initialized before allocation:
if (!$resource->getPHID()) {
throw new Exception(pht(
'Build resources with newResourceTemplate(), not new DrydockResource().'));
}
$resource->allocateResource(); Type guard
// Guard: a allocatable template has a PHID and PENDING status.
function isAllocatableTemplate(DrydockResource $resource) {
return (bool)$resource->getPHID();
} Try / catch
catch (Exception $ex) { on 'no generated PHID', replace direct construction with $this->newResourceTemplate($blueprint) inside the blueprint implementation; nothing else makes the object allocatable } Prevention
- Always create resources through newResourceTemplate() in DrydockBlueprintImplementation subclasses
- Never call new DrydockResource() in allocation code paths
- Lint custom blueprints for direct resource construction during code review
When it happens
Trigger: Custom blueprint code doing `id(new DrydockResource())->save()` then `->allocateResource()`; copying an allocated resource object and trying to re-allocate the clone; bypassing newResourceTemplate() because it is protected on the implementation class.
Common situations: Writing a first custom DrydockBlueprintImplementation; refactoring stock blueprints and dropping the template call; test scaffolding that constructs resources directly.
Related errors
- Trying to allocate a resource from the wrong status. Status
- This blueprint ("%s") does not define any Almanac Service PH
- Some of the Almanac Services defined by this blueprint could
- Repository PHID "%s" does not exist.
- Repository ("%s") has unsupported VCS ("%s").
AI-assisted analysis of phacility/phabricator@5720a38cfe (2026-08-21).
Data as JSON: /api/errors/ebac6e5b5ecff561.
Report an issue: GitHub.