Root org unit not accessible

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

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 :

select * from usermembership where userinfoid = 5604235

SELECT 0

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

\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)
1 Like

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.

1 Like

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.

1 Like

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

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

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

\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

1 Like

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

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

update userinfo set creatoruserid=56 where creatoruserid = 4586625

and it’s fixed

probably a missing foreign key constraint ?

1 Like

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.

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

Happy New Year!