# Root org unit not accessible

**URL:** <https://community.dhis2.org/t/root-org-unit-not-accessible/61349>\
**Category:** Support - Assistance technique\
**Created:** [30 September 2024 11:14 UTC](https://community.dhis2.org/t/root-org-unit-not-accessible/61349 "2024-09-30T11:14:54Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![mutali](https://dhis2.b-cdn.net/user_avatar/community.dhis2.org/mutali/32/33661_2.png) [@mutali](https://community.dhis2.org/u/mutali)\
**Post date:** [30 September 2024 11:14 UTC](https://community.dhis2.org/t/root-org-unit-not-accessible/61349/1 "2024-09-30T11:14:54Z")

</div>

The maintenance app is not opening, and the error message from console is this one:

caught (in promise) {“organisationUnits”:}{“httpStatus”:“Bad Request”,“httpStatusCode”:400,“status”:“ERROR”,“message”:“Entity `org.hisp.dhis.user.User` with identifier value `5604235` does not exist (through reference chain: org.hisp.dhis.organisationunit.OrganisationUnit["users"])”}

Any hit how to troubleshoot this?

getting same arror on Org unit API

---

<div class="post-metadata">

**Author:** ![Stephan\_Mestach](https://dhis2.b-cdn.net/user_avatar/community.dhis2.org/stephan_mestach/32/40053_2.png) [@Stephan\_Mestach](https://community.dhis2.org/u/Stephan_Mestach)\
**Post date:** [1 October 2024 08:38 UTC](https://community.dhis2.org/t/root-org-unit-not-accessible/61349/2 "2024-10-01T08:38:50Z")

</div>

Looks like your db is no more coherent  
Did you delete some data through sql ?  
Are you logged in as admin ?

It looks like the user `5604235` is still referenced by orgUnits  
Can you check that the table `usermembership` doesn’t contains a record for that user :

```auto
select * from usermembership where userinfoid = 5604235

SELECT 0

```

What is strange, normally you need to have the constraints to prevent such incoherence

```auto
\d usermembership
+--------------------+--------+-----------+
| Column | Type | Modifiers |
|--------------------+--------+-----------|
| userinfoid | bigint | not null |
| organisationunitid | bigint | not null |
+--------------------+--------+-----------+
Indexes:
    "usermembership_pkey" PRIMARY KEY, btree (userinfoid, organisationunitid)
Foreign-key constraints:
    "fk_userinfo_organisationunitid" FOREIGN KEY (organisationunitid) REFERENCES organisationunit(organisationunitid)
    "fk_usermembership_userinfoid" FOREIGN KEY (userinfoid) REFERENCES userinfo(userinfoid)

```

---

<div class="post-metadata">

**Author:** ![mutali](https://dhis2.b-cdn.net/user_avatar/community.dhis2.org/mutali/32/33661_2.png) [@mutali](https://community.dhis2.org/u/mutali)\
**Post date:** [1 October 2024 12:34 UTC](https://community.dhis2.org/t/root-org-unit-not-accessible/61349/3 "2024-10-01T12:34:11Z")

</div>

Hi Stephan,  
I am logged as superuser , but not admin as user.  
May be someone did some query on backend, I m not sure, I m given a copy to troubleshoot only.  
I did run the query but did not find the specific user in any table. In case you found any other idea, let me know.  
I can how ever access maintenance app by assigning the user to other Org unit for capture other than root.  
Thank you.

---

<div class="post-metadata">

**Author:** ![Stephan\_Mestach](https://dhis2.b-cdn.net/user_avatar/community.dhis2.org/stephan_mestach/32/40053_2.png) [@Stephan\_Mestach](https://community.dhis2.org/u/Stephan_Mestach)\
**Post date:** [1 October 2024 13:14 UTC](https://community.dhis2.org/t/root-org-unit-not-accessible/61349/4 "2024-10-01T13:14:22Z")

</div>

if someone deleted the user via sql I would restart the instance.

the user info is something heavily cached so perhaps the java process isn’t aware of the deletion.

I think there’s an option without restarting in the data administration page.

---

<div class="post-metadata">

**Author:** ![Stephan\_Mestach](https://dhis2.b-cdn.net/user_avatar/community.dhis2.org/stephan_mestach/32/40053_2.png) [@Stephan\_Mestach](https://community.dhis2.org/u/Stephan_Mestach)\
**Post date:** [13 December 2024 14:40 UTC](https://community.dhis2.org/t/root-org-unit-not-accessible/61349/5 "2024-12-13T14:40:48Z")

</div>

interesting I have a similar problem on 2.40.5

accessing : `/api/userRoles/pNcEKvKF7K2?fields=id,name,users` and  
`/api/userGroups/XW1ly5pIn8f?fields=id,name,users`  
on my server trigger a

```auto
Entity org.hisp.dhis.user.User with identifier value 4586625 does not exist (through reference chain: org.hisp.dhis.user.UserRole["users"])'

```

same problem on `/api/userGroups/XW1ly5pIn8f?fields=id,name,users`

this query doesn’t return anything

```auto
SELECT *
  FROM userrolemembers
  WHERE userid NOT IN (SELECT userinfoid FROM userinfo)
     OR userroleid NOT IN (SELECT userroleid FROM userrole);

```

I’ve verified the constraints are there and enforced

```auto
\d userrolemembers
+------------+--------+-----------+
| Column | Type | Modifiers |
|------------+--------+-----------|
| userroleid | bigint | not null |
| userid | bigint | not null |
+------------+--------+-----------+
Indexes:
    "userrolemembers_pkey" PRIMARY KEY, btree (userid, userroleid)
Foreign-key constraints:
    "fk_userrolemembers_userid" FOREIGN KEY (userid) REFERENCES userinfo(userinfoid)
    "fk_userrolemembers_userroleid" FOREIGN KEY (userroleid) REFERENCES userrole(userroleid)

Time: 0.025s

SELECT conname, convalidated, pg_get_constraintdef(oid)
 FROM pg_constraint
 WHERE conrelid = 'userrolemembers'::regclass;
-[RECORD 1]-------------------------
conname | fk_userrolemembers_userid
convalidated | True
pg_get_constraintdef | FOREIGN KEY (userid) REFERENCES userinfo(userinfoid)
-[RECORD 2]-------------------------
conname | fk_userrolemembers_userroleid
convalidated | True
pg_get_constraintdef | FOREIGN KEY (userroleid) REFERENCES userrole(userroleid)
-[RECORD 3]-------------------------
conname | userrolemembers_pkey
convalidated | True
pg_get_constraintdef | PRIMARY KEY (userid, userroleid)

```

@Gassim can you check with a developer

- I’m looking at the correct table ?
- is it possible that some hibernate subtleties might interfere (hashCode/equals implementation ?)

I must admit  
I’m lost

---

<div class="post-metadata">

**Author:** ![Stephan\_Mestach](https://dhis2.b-cdn.net/user_avatar/community.dhis2.org/stephan_mestach/32/40053_2.png) [@Stephan\_Mestach](https://community.dhis2.org/u/Stephan_Mestach)\
**Post date:** [13 December 2024 15:48 UTC](https://community.dhis2.org/t/root-org-unit-not-accessible/61349/6 "2024-12-13T15:48:09Z")

</div>

So I found the source of the problem and a workaround  
I dumped the `userrolemembers` and `userinfo`

```auto
pg_dump -t userinfo $DATABASE_URL > test_dump.sql
grep 4586625 test_dump.sql

```

and found a reference to the id in the error message

one user was referencing this user in the `creatoruserid`  
I’ve updated the creatoruserid to something that exist

```auto
update userinfo set creatoruserid=56 where creatoruserid = 4586625

```

and it’s fixed

probably a missing foreign key constraint ?

---

<div class="post-metadata">

**Author:** ![Gassim](https://dhis2.b-cdn.net/user_avatar/community.dhis2.org/gassim/32/35347_2.png) [@Gassim](https://community.dhis2.org/u/Gassim)\
**Post date:** [1 January 2025 15:30 UTC](https://community.dhis2.org/t/root-org-unit-not-accessible/61349/7 "2025-01-01T15:30:36Z")

</div>

Hi @Stephan_Mestach

Thank you for your updates and help with this post. Usually issues that are happening to a specific database are usually difficult to resolve unless some debugging is done on the database itself.

> [@Stephan\_Mestach](#):
>
> one user was referencing this user in the `creatoruserid`  
> I’ve updated the creatoruserid to something that exist

It’s quite interesting how ‘creatoruserid’ would reference a non-existent id 🤔 . I’m FWD this to one of the developers as you suggested. Really sorry for the late reply.

Happy New Year!
