Server: Unable to delete User

Created on 11 Jul 2019  路  11Comments  路  Source: nextcloud/server

Steps to reproduce

  1. add new user with a php-skript
  2. add Attribute 'address' extrakted from a csv.file in ANSI that contains a "脽" (no Problem with UTF-8)
  3. login as admin in the nextcloud webinterface

Actual behaviour

  • User dont appear in Users --> everyone
    when scrolling down: all users, who would be listed after that user are not listed and the message "An error occured during the request. Unable to proceed" appears
    in loggig appears:
    TypeError: Argument 1 passed to OC\Accounts\AccountManager::addMissingDefaultValues() must be of the type array, null given, called in /var/www/html/nextcloud/lib/private/Accounts/AccountManager.php on line 139 at /var/www/html/nextcloud/lib/private/Accounts/AccountManager.php#176
  • when clicking on a Group this user is a member of, none of the users is shown and the message "An error occured during the request. Unable to proceed" appears.
  • It is impossible to delete the user in the web interface because he is not listed.

With a php skript following oparations work:

  • Get users: shows all users and inclusive that user
  • Get groups that user is a member of
  • Add that user to a group
  • Change the Attribute 'displayname'

With a php skript following oparations do not work:

  • Disabe that user
  • Delete that user
  • Change the attribute 'address'
  • Remove that user from a group
  • Change the password of that user
    always the same log-message: TypeError: Argument 1 passed to OC\Accounts\AccountManager::addMissingDefaultValues() must be of the type array, null given, called in /var/www/html/nextcloud/lib/private/Accounts/AccountManager.php on line 139 at /var/www/html/nextcloud/lib/private/Accounts/AccountManager.php#176

Server configuration

Operating system:
Ubuntu 18-04 server

Web server:
apache2

Database:
mariadb-server

PHP version:
PHP 7.2.19

Nextcloud version: (see Nextcloud admin page)
Nextcloud 16.0.3

Updated from an older Nextcloud/ownCloud or fresh install:
fresh install

Where did you install Nextcloud from:
wget https://download.nextcloud.com/server/releases/latest.tar.bz2

List of activated apps:
calendar

Are you using encryption: yes/no
no

Is there a quick solution to get rid of this user?

0. Needs triage bug

All 11 comments

Hmm. Not sure how to reproduce properly. We restore some json encoded data from the database but could not decode it. Please backup your database before you try to patch below. No warranty.

Index: lib/private/Accounts/AccountManager.php
IDEA additional info:
Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP
<+>UTF-8
===================================================================
--- lib/private/Accounts/AccountManager.php (revision 5c9b19289be0aa195fb0d8e26952c6558464c6cc)
+++ lib/private/Accounts/AccountManager.php (date 1562802719000)
@@ -135,6 +135,9 @@
        }

        $userDataArray = json_decode($result[0]['data'], true);
+       if ($userDataArray === null || json_last_error() !== JSON_ERROR_NONE) {
+           $userDataArray = $this->buildDefaultUserRecord($user);
+       }

        $userDataArray = $this->addMissingDefaultValues($userDataArray);

cc @schiessle

This patch works fine !
Thank you very very much!!!!!!!!

@ThomasKuehner So can this issue be closed as resolved?

@wiswedel this fix should be added into the code. Otherwise you have to change the code after every update. We got the same issue after migrating Owncloud to Nextcloud and the snippet fixed it.

Index: lib/private/Accounts/AccountManager.php
IDEA additional info:
Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP
<+>UTF-8
===================================================================
--- lib/private/Accounts/AccountManager.php (revision 99358d70e88e42af72a38154945efa71229779c3)
+++ lib/private/Accounts/AccountManager.php (date 1570626720250)
@@ -135,6 +135,10 @@
        }

        $userDataArray = json_decode($result[0]['data'], true);
+       if ($userDataArray === null || json_last_error() !== JSON_ERROR_NONE) {
+           \OC::$server->getLogger()->warning('Could not decode data from db: ' . json_last_error_msg());
+           $userDataArray = $this->buildDefaultUserRecord($user);
+       }

        $userDataArray = $this->addMissingDefaultValues($userDataArray);

@levigo-systems mind to apply this patch? I'm still not sure how to push the wrong data into the db.

A better way would be to deploy a fix for the invalid JSON in the oc_accounts table. Maybe a new CLI command "db:convert-invalid-json" or something like that.

But if that's not possible i recommend to apply this patch above.

We can integrate the patch. But the patch just does the damage control after the bug. It doesn't fix the bug that we even insert invalid json.

Does anyone know where this might come from? Did you run manual SQL queries to modify it?

Did you run manual SQL queries to modify it?

We know of no changes directly in the database.

add new user with a php-skript

Probably they use some app to create users. I agree to @ChristophWurst and @levigo-systems in general (fix bugs instead of adding workarounds) but our code should not fail if some more or less important data is missing ;)

Is there a way to fix the broken JSON entry's manually?
Otherwise after every update the patch most be applied.

Is there a way to fix the broken JSON entry's manually?

Inspect the row, fix it and update the row

Otherwise after every update the patch most be applied.

No, you don't as of https://github.com/nextcloud/server/pull/17494

Was this page helpful?
0 / 5 - 0 ratings