{"record":{"id":"27638a7d9fd87128","repo":"passbolt/passbolt_api","slug":"relation-creation-error-could-not-retrieve-corresponding","errorCode":null,"errorMessage":"Relation creation error: Could not retrieve corresponding entries","messagePattern":"Relation creation error: Could not retrieve corresponding entries","errorType":"exception","errorClass":null,"httpStatus":500,"severity":"error","filePath":"plugins/PassboltEe/DirectorySync/src/Model/Table/DirectoryRelationsTable.php","lineNumber":161,"sourceCode":"     */\n    public function createFromGroupUser(GroupsUser $groupUser): mixed\n    {\n        $DirectoryEntries = TableRegistry::getTableLocator()->get('Passbolt/DirectorySync.DirectoryEntries');\n\n        $groupEntry = $DirectoryEntries\n            ->find()\n            ->select('id')\n            ->where(['foreign_model' => Alias::MODEL_GROUPS, 'foreign_key' => $groupUser->group_id])\n            ->first();\n\n        $userEntry = $DirectoryEntries\n            ->find()\n            ->select('id')\n            ->where(['foreign_model' => Alias::MODEL_USERS, 'foreign_key' => $groupUser->user_id])\n            ->first();\n\n        if (!$groupEntry || !$userEntry) {\n            throw new Exception('Relation creation error: Could not retrieve corresponding entries');\n        }\n\n        $relation = [\n            'id' => $groupUser->id,\n            'parent_key' => $groupEntry->get('id'),\n            'child_key' => $userEntry->get('id'),\n        ];\n\n        return $this->createOrUpdate($relation);\n    }\n\n    /**\n     * Create or update.\n     *\n     * @param array $data data\n     * @return \\Cake\\Datasource\\EntityInterface|\\Passbolt\\DirectorySync\\Model\\Entity\\DirectoryIgnore|mixed|bool|false\n     */\n    public function createOrUpdate(array $data): mixed","sourceCodeStart":143,"sourceCodeEnd":179,"githubUrl":"https://github.com/passbolt/passbolt_api/blob/31c1bbc10f32808a607fa9bd81891e898779c0bc/plugins/PassboltEe/DirectorySync/src/Model/Table/DirectoryRelationsTable.php#L143-L179","documentation":"DirectoryRelationsTable::createFromGroupUser builds a directory relation linking a group entry to a user entry in directory_entries. It first looks up the group's and the user's directory entries by foreign_key; if either lookup returns null it throws a generic Exception, because the relation cannot be created without both parent and child entries.","triggerScenarios":"Calling createFromGroupUser($groupUser) during a group-user sync when either the group's directory entry (foreign_model Groups, foreign_key group_id) or the user's entry (foreign_model Users, foreign_key user_id) is missing from directory_entries.","commonSituations":"Partial LDAP sync where the group was synced but the member user wasn't (or vice versa); entries purged by orphan cleanup between syncs; sync order processing group memberships before users are created; deleted LDAP user still present in group memberships.","solutions":["Ensure users are synced/created before processing group memberships in your sync flow.","Verify both directory_entries rows exist: query DirectoryEntries for foreign_key = user_id and group_id before calling createFromGroupUser.","Re-run a full directory sync to rebuild missing directory_entries rows.","Investigate why the entry is missing — often a previous sync error or manual deletion from directory_entries."],"exampleFix":"// before\n$this->DirectoryRelations->createFromGroupUser($groupUser);\n// after\n$exists = $this->DirectoryEntries->find()->where(['foreign_model' => Alias::MODEL_USERS, 'foreign_key' => $groupUser->user_id])->first();\nif ($exists) {\n    $this->DirectoryRelations->createFromGroupUser($groupUser);\n}","handlingStrategy":"validation","validationCode":"$DirectoryEntries = TableRegistry::getTableLocator()->get('Passbolt/DirectorySync.DirectoryEntries');\n$ok = $DirectoryEntries->find()->where(['foreign_model' => Alias::MODEL_GROUPS, 'foreign_key' => $groupUser->group_id])->first()\n  && $DirectoryEntries->find()->where(['foreign_model' => Alias::MODEL_USERS, 'foreign_key' => $groupUser->user_id])->first();","typeGuard":"$hasEntries = fn(GroupsUser $gu): bool =>\n    (bool)$this->DirectoryEntries->find()->where(['foreign_model' => Alias::MODEL_GROUPS, 'foreign_key' => $gu->group_id])->first()\n    && (bool)$this->DirectoryEntries->find()->where(['foreign_model' => Alias::MODEL_USERS, 'foreign_key' => $gu->user_id])->first();","tryCatchPattern":"try {\n    $this->DirectoryRelations->createFromGroupUser($groupUser);\n} catch (Exception $e) {\n    // missing directory_entries row — queue for a full re-sync instead of crashing\n}","preventionTips":["Sync users before processing group memberships","Verify both directory_entries rows exist before creating relations","Run full re-syncs periodically to rebuild missing entries","Never manually delete directory_entries rows without a following full sync"],"tags":["passbolt","directory-sync","ldap","missing-entry","relation"],"backgroundTag":"entity-not-found","analyzedSha":"31c1bbc10f32808a607fa9bd81891e898779c0bc","analyzedAt":"2026-09-17T00:04:38.960Z","contentChangedAt":"2026-09-17T00:04:38.960Z","schemaVersion":2},"datasetVersion":"2026-09-21T04:17:39.646Z"}