nextcloud / nextcloud/mail

MultipleObjectsReturnedException during provisioning followed by DBAL Exception during cleanup/unprovisioning

Open
#12,634 1 comment 0 reactions 1 assignee View on GitHub

@ChristophWurst is already working on this.

Since Mar 24, 2026.

2. developing bug
Dominant language
JavaScript
Stars
1k
Forks
348
Avg merge
12h 28m
Merged PRs (30d)
91

Description

Steps to reproduce
  1. Configure automatic account provisioning (e.g., using "Use master password").
  2. User logs in and opens the Mail app.
  3. The app crashes with a 500 Internal Server Error (Bug 1).
  4. Attempt to delete the provisioned account via the UI to resolve the conflict.
  5. The UI shows an error toast, and the deletion fails due to the DBAL exception (Bug 2).
Expected behavior
  1. Provisioning should strictly ensure only one account is created/returned per user.
  2. Unprovisioning/Deleting an account should execute valid SQL queries without deprecated table aliases.
Actual behavior

Setting up automatic account provisioning via Master Password leads to a fatal error loop in the Mail app. The issue consists of two linked bugs:

Bug 1 (Initial Crash): When a user opens the Mail app, the provisioning logic seems to create or retrieve multiple provisioned accounts for the same user, resulting in a MultipleObjectsReturnedException (Did not expect more than one result when executing: query "SELECT * FROM *PREFIX*mail_accounts WHERE (user_id = :dcValue1) AND (provisioning_id IS NOT NULL)"). This causes an HTTP 500 error, blocking the user from using the app.

Bug 2 (Failing Rollback/Cleanup): When the app attempts to clean up the orphaned aliases/accounts after the failure (or when an admin tries to delete the provisioned account via the UI/CLI), the process crashes due to deprecated SQL syntax in OCA\Mail\Db\AliasMapper. The Nextcloud DBAL layer rejects the DELETE query because it uses a table alias (DELETE queries with alias are no longer supported and the provided alias is ignored). The subsequent WHERE clause referencing accounts.user_id then throws an Unknown column exception, completely breaking the unprovisioning process.

Mail app version

5.7.4

Nextcloud version

32.0.6.1

Mailserver or service

postfix & dovecot

Operating system

docker on ubuntu 24.4 server

PHP engine version

PHP 8.3

Nextcloud memory caching

\OC\Memcache\APCu & \OC\Memcache\Redis

Web server

Nginx

Database

MariaDB

Additional info

Bug 1 (Multiple Objects Exception):

{
  "reqId": "ZdjuiKwe2ov6qDRKEBg5",
  "level": 3,
  "time": "2026-03-22T02:23:48+01:00",
  "app": "index",
  "method": "GET",
  "url": "/apps/mail/",
  "message": "Did not expect more than one result when executing: query \"SELECT * FROM `*PREFIX*mail_accounts` WHERE (`user_id` = :dcValue1) AND (`provisioning_id` IS NOT NULL)\"; ",
  "exception": {
    "Exception": "OCP\\AppFramework\\Db\\MultipleObjectsReturnedException",
    "Message": "Did not expect more than one result when executing: query \"SELECT * FROM `*PREFIX*mail_accounts` WHERE (`user_id` = :dcValue1) AND (`provisioning_id` IS NOT NULL)\";",
    "Trace": [
      {
        "file": "/var/www/html/lib/public/AppFramework/Db/QBMapper.php",
        "line": 375,
        "function": "findOneQuery",
        "class": "OCP\\AppFramework\\Db\\QBMapper"
      }
    ]
  }
}

Bug 2 (DBAL Delete Alias Exception):

{
  "reqId": "ZdjuiKwe2ov6qDRKEBg5",
  "level": 0,
  "time": "2026-03-22T02:23:48+01:00",
  "app": "no app in context",
  "method": "GET",
  "url": "/apps/mail/",
  "message": "DELETE queries with alias are no longer supported and the provided alias is ignored",
  "exception": {
    "Exception": "InvalidArgumentException",
    "Message": "Table alias provided for DELETE query",
    "Trace": [
      {
        "file": "/var/www/html/custom_apps/mail/lib/Db/AliasMapper.php",
        "line": 114,
        "function": "delete",
        "class": "OC\\DB\\QueryBuilder\\QueryBuilder",
        "type": "->",
        "args": [
          "mail_aliases",
          "aliases"
        ]
      },
      {
        "file": "/var/www/html/custom_apps/mail/lib/Service/Provisioning/Manager.php",
        "line": 204,
        "function": "deleteProvisionedAliasesByUid",
        "class": "OCA\\Mail\\Db\\AliasMapper"
      }
    ]
  }
}
{
  "reqId": "ZdjuiKwe2ov6qDRKEBg5",
  "level": 2,
  "time": "2026-03-22T02:23:48+01:00",
  "app": "mail",
  "method": "GET",
  "url": "/apps/mail/",
  "message": "Error during deletion of mail provisioning profile for user with UID solero",
  "exception": {
    "Exception": "OC\\DB\\Exceptions\\DbalException",
    "Message": "An exception occurred while executing a query: SQLSTATE[42S22]: Column not found: 1054 Unknown column 'accounts.user_id' in 'WHERE'",
    "Code": 1054,
    "Trace": [
      {
        "file": "/var/www/html/lib/private/DB/ConnectionAdapter.php",
        "line": 69,
        "function": "wrap",
        "class": "OC\\DB\\Exceptions\\DbalException",
        "type": "::",
        "args": [
          {
            "__class__": "Doctrine\\DBAL\\Exception\\InvalidFieldNameException"
          },
          "",
          "DELETE FROM `*PREFIX*mail_aliases` aliases WHERE (`accounts`.`user_id` = :dcValue1) AND (`provisioning_id` IS NOT NULL)"
        ]
      }
    ]
  }
}

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.