NextCloud 20: Logs Fatal Error "InvalidFieldNameException"

After upgrading from NC19 to NC20 I’ve had a rather glorious run, everything works like a dream and it’s sweet as.

But I’m checking logs in response to a sync error and I find it hard to find anything as it’s flooded with these Fatal Errors related to Doctrine\DBAL\Exception\InvalidFieldNameException.

Here’s a copy of one (Only the RAW Copy works the Formatted Copy does not work, in either FF or Chrome it seems). This does relate to the file reported though, and it appears in the URL field. So I’m guessing the desktop client is trying to delete. I’m wondering how to interpret this it looks like a bug given the core message is: column \"file_id\" of relation \"oc_group_folders_trash\" … Is this worth filing an issue on github?

{
"reqId": "lRQAduiu2MlblCCylw0k",
"level": 4,
"time": "2020-11-28T15:35:09+11:00",
"remoteAddr": "192.168.0.11",
"user": "bernd",
"app": "webdav",
"method": "DELETE",
"url": "/remote.php/dav/files/bernd/HoGS/Data%20and%20information/Membership/.~lock.MASTER%20Members%20List.xlsx%23",
"message": {
    "Exception": "Doctrine\\DBAL\\Exception\\InvalidFieldNameException",
    "Message": "An exception occurred while executing 'INSERT INTO \"oc_group_folders_trash\" (\"folder_id\", \"name\", \"deleted_time\", \"original_location\", \"file_id\") VALUES(?, ?, ?, ?, ?)' with params [1, \".~lock.MASTER Members List.xlsx#\", 1606538109, \"Data and information\\/Membership\\/.~lock.MASTER Members List.xlsx#\", 123964]:\n\nSQLSTATE[42703]: Undefined column: 7 ERROR:  column \"file_id\" of relation \"oc_group_folders_trash\" does not exist\nLINE 1: ...id\", \"name\", \"deleted_time\", \"original_location\", \"file_id\")...\n                                                             ^",
    "Code": 0,
    "Trace": [{
        "file": "/var/www/html/nextcloud/3rdparty/doctrine/dbal/lib/Doctrine/DBAL/DBALException.php",
        "line": 169,
        "function": "convertException",
        "class": "Doctrine\\DBAL\\Driver\\AbstractPostgreSQLDriver",
        "type": "->"
    }, {
        "file": "/var/www/html/nextcloud/3rdparty/doctrine/dbal/lib/Doctrine/DBAL/DBALException.php",
        "line": 149,
        "function": "wrapException",
        "class": "Doctrine\\DBAL\\DBALException",
        "type": "::"
    }, {
        "file": "/var/www/html/nextcloud/3rdparty/doctrine/dbal/lib/Doctrine/DBAL/Connection.php",
        "line": 1071,
        "function": "driverExceptionDuringQuery",
        "class": "Doctrine\\DBAL\\DBALException",
        "type": "::"
    }, {
        "file": "/var/www/html/nextcloud/lib/private/DB/Connection.php",
        "line": 222,
        "function": "executeUpdate",
        "class": "Doctrine\\DBAL\\Connection",
        "type": "->"
    }, {
        "file": "/var/www/html/nextcloud/3rdparty/doctrine/dbal/lib/Doctrine/DBAL/Query/QueryBuilder.php",
        "line": 209,
        "function": "executeUpdate",
        "class": "OC\\DB\\Connection",
        "type": "->"
    }, {
        "file": "/var/www/html/nextcloud/lib/private/DB/QueryBuilder/QueryBuilder.php",
        "line": 217,
        "function": "execute",
        "class": "Doctrine\\DBAL\\Query\\QueryBuilder",
        "type": "->"
    }, {
        "file": "/var/www/html/nextcloud/apps/groupfolders/lib/Trash/TrashManager.php",
        "line": 53,
        "function": "execute",
        "class": "OC\\DB\\QueryBuilder\\QueryBuilder",
        "type": "->"
    }, {
        "file": "/var/www/html/nextcloud/apps/groupfolders/lib/Trash/TrashBackend.php",
        "line": 180,
        "function": "addTrashItem",
        "class": "OCA\\GroupFolders\\Trash\\TrashManager",
        "type": "->"
    }, {
        "file": "/var/www/html/nextcloud/apps/files_trashbin/lib/Trash/TrashManager.php",
        "line": 103,
        "function": "moveToTrash",
        "class": "OCA\\GroupFolders\\Trash\\TrashBackend",
        "type": "->"
    }, {
        "file": "/var/www/html/nextcloud/apps/files_trashbin/lib/Storage.php",
        "line": 192,
        "function": "moveToTrash",
        "class": "OCA\\Files_Trashbin\\Trash\\TrashManager",
        "type": "->"
    }, {
        "file": "/var/www/html/nextcloud/apps/files_trashbin/lib/Storage.php",
        "line": 99,
        "function": "doDelete",
        "class": "OCA\\Files_Trashbin\\Storage",
        "type": "->"
    }, {
        "file": "/var/www/html/nextcloud/lib/private/Files/View.php",
        "line": 1167,
        "function": "unlink",
        "class": "OCA\\Files_Trashbin\\Storage",
        "type": "->"
    }, {
        "file": "/var/www/html/nextcloud/lib/private/Files/View.php",
        "line": 724,
        "function": "basicOperation",
        "class": "OC\\Files\\View",
        "type": "->"
    }, {
        "file": "/var/www/html/nextcloud/apps/dav/lib/Connector/Sabre/File.php",
        "line": 466,
        "function": "unlink",
        "class": "OC\\Files\\View",
        "type": "->"
    }, {
        "file": "/var/www/html/nextcloud/3rdparty/sabre/dav/lib/DAV/Tree.php",
        "line": 183,
        "function": "delete",
        "class": "OCA\\DAV\\Connector\\Sabre\\File",
        "type": "->"
    }, {
        "file": "/var/www/html/nextcloud/3rdparty/sabre/dav/lib/DAV/CorePlugin.php",
        "line": 295,
        "function": "delete",
        "class": "Sabre\\DAV\\Tree",
        "type": "->"
    }, {
        "file": "/var/www/html/nextcloud/3rdparty/sabre/event/lib/WildcardEmitterTrait.php",
        "line": 89,
        "function": "httpDelete",
        "class": "Sabre\\DAV\\CorePlugin",
        "type": "->"
    }, {
        "file": "/var/www/html/nextcloud/3rdparty/sabre/dav/lib/DAV/Server.php",
        "line": 474,
        "function": "emit",
        "class": "Sabre\\DAV\\Server",
        "type": "->"
    }, {
        "file": "/var/www/html/nextcloud/3rdparty/sabre/dav/lib/DAV/Server.php",
        "line": 251,
        "function": "invokeMethod",
        "class": "Sabre\\DAV\\Server",
        "type": "->"
    }, {
        "file": "/var/www/html/nextcloud/3rdparty/sabre/dav/lib/DAV/Server.php",
        "line": 319,
        "function": "start",
        "class": "Sabre\\DAV\\Server",
        "type": "->"
    }, {
        "file": "/var/www/html/nextcloud/apps/dav/lib/Server.php",
        "line": 332,
        "function": "exec",
        "class": "Sabre\\DAV\\Server",
        "type": "->"
    }, {
        "file": "/var/www/html/nextcloud/apps/dav/appinfo/v2/remote.php",
        "line": 35,
        "function": "exec",
        "class": "OCA\\DAV\\Server",
        "type": "->"
    }, {
        "file": "/var/www/html/nextcloud/remote.php",
        "line": 167,
        "args": ["/var/www/html/nextcloud/apps/dav/appinfo/v2/remote.php"],
        "function": "require_once"
    }],
    "File": "/var/www/html/nextcloud/3rdparty/doctrine/dbal/lib/Doctrine/DBAL/Driver/AbstractPostgreSQLDriver.php",
    "Line": 60,
    "Previous": {
        "Exception": "Doctrine\\DBAL\\Driver\\PDOException",
        "Message": "SQLSTATE[42703]: Undefined column: 7 ERROR:  column \"file_id\" of relation \"oc_group_folders_trash\" does not exist\nLINE 1: ...id\", \"name\", \"deleted_time\", \"original_location\", \"file_id\")...\n                                                             ^",
        "Code": "42703",
        "Trace": [{
            "file": "/var/www/html/nextcloud/3rdparty/doctrine/dbal/lib/Doctrine/DBAL/Connection.php",
            "line": 1062,
            "function": "execute",
            "class": "Doctrine\\DBAL\\Driver\\PDOStatement",
            "type": "->"
        }, {
            "file": "/var/www/html/nextcloud/lib/private/DB/Connection.php",
            "line": 222,
            "function": "executeUpdate",
            "class": "Doctrine\\DBAL\\Connection",
            "type": "->"
        }, {
            "file": "/var/www/html/nextcloud/3rdparty/doctrine/dbal/lib/Doctrine/DBAL/Query/QueryBuilder.php",
            "line": 209,
            "function": "executeUpdate",
            "class": "OC\\DB\\Connection",
            "type": "->"
        }, {
            "file": "/var/www/html/nextcloud/lib/private/DB/QueryBuilder/QueryBuilder.php",
            "line": 217,
            "function": "execute",
            "class": "Doctrine\\DBAL\\Query\\QueryBuilder",
            "type": "->"
        }, {
            "file": "/var/www/html/nextcloud/apps/groupfolders/lib/Trash/TrashManager.php",
            "line": 53,
            "function": "execute",
            "class": "OC\\DB\\QueryBuilder\\QueryBuilder",
            "type": "->"
        }, {
            "file": "/var/www/html/nextcloud/apps/groupfolders/lib/Trash/TrashBackend.php",
            "line": 180,
            "function": "addTrashItem",
            "class": "OCA\\GroupFolders\\Trash\\TrashManager",
            "type": "->"
        }, {
            "file": "/var/www/html/nextcloud/apps/files_trashbin/lib/Trash/TrashManager.php",
            "line": 103,
            "function": "moveToTrash",
            "class": "OCA\\GroupFolders\\Trash\\TrashBackend",
            "type": "->"
        }, {
            "file": "/var/www/html/nextcloud/apps/files_trashbin/lib/Storage.php",
            "line": 192,
            "function": "moveToTrash",
            "class": "OCA\\Files_Trashbin\\Trash\\TrashManager",
            "type": "->"
        }, {
            "file": "/var/www/html/nextcloud/apps/files_trashbin/lib/Storage.php",
            "line": 99,
            "function": "doDelete",
            "class": "OCA\\Files_Trashbin\\Storage",
            "type": "->"
        }, {
            "file": "/var/www/html/nextcloud/lib/private/Files/View.php",
            "line": 1167,
            "function": "unlink",
            "class": "OCA\\Files_Trashbin\\Storage",
            "type": "->"
        }, {
            "file": "/var/www/html/nextcloud/lib/private/Files/View.php",
            "line": 724,
            "function": "basicOperation",
            "class": "OC\\Files\\View",
            "type": "->"
        }, {
            "file": "/var/www/html/nextcloud/apps/dav/lib/Connector/Sabre/File.php",
            "line": 466,
            "function": "unlink",
            "class": "OC\\Files\\View",
            "type": "->"
        }, {
            "file": "/var/www/html/nextcloud/3rdparty/sabre/dav/lib/DAV/Tree.php",
            "line": 183,
            "function": "delete",
            "class": "OCA\\DAV\\Connector\\Sabre\\File",
            "type": "->"
        }, {
            "file": "/var/www/html/nextcloud/3rdparty/sabre/dav/lib/DAV/CorePlugin.php",
            "line": 295,
            "function": "delete",
            "class": "Sabre\\DAV\\Tree",
            "type": "->"
        }, {
            "file": "/var/www/html/nextcloud/3rdparty/sabre/event/lib/WildcardEmitterTrait.php",
            "line": 89,
            "function": "httpDelete",
            "class": "Sabre\\DAV\\CorePlugin",
            "type": "->"
        }, {
            "file": "/var/www/html/nextcloud/3rdparty/sabre/dav/lib/DAV/Server.php",
            "line": 474,
            "function": "emit",
            "class": "Sabre\\DAV\\Server",
            "type": "->"
        }, {
            "file": "/var/www/html/nextcloud/3rdparty/sabre/dav/lib/DAV/Server.php",
            "line": 251,
            "function": "invokeMethod",
            "class": "Sabre\\DAV\\Server",
            "type": "->"
        }, {
            "file": "/var/www/html/nextcloud/3rdparty/sabre/dav/lib/DAV/Server.php",
            "line": 319,
            "function": "start",
            "class": "Sabre\\DAV\\Server",
            "type": "->"
        }, {
            "file": "/var/www/html/nextcloud/apps/dav/lib/Server.php",
            "line": 332,
            "function": "exec",
            "class": "Sabre\\DAV\\Server",
            "type": "->"
        }, {
            "file": "/var/www/html/nextcloud/apps/dav/appinfo/v2/remote.php",
            "line": 35,
            "function": "exec",
            "class": "OCA\\DAV\\Server",
            "type": "->"
        }, {
            "file": "/var/www/html/nextcloud/remote.php",
            "line": 167,
            "args": ["/var/www/html/nextcloud/apps/dav/appinfo/v2/remote.php"],
            "function": "require_once"
        }],
        "File": "/var/www/html/nextcloud/3rdparty/doctrine/dbal/lib/Doctrine/DBAL/Driver/PDOStatement.php",
        "Line": 129,
        "Previous": {
            "Exception": "PDOException",
            "Message": "SQLSTATE[42703]: Undefined column: 7 ERROR:  column \"file_id\" of relation \"oc_group_folders_trash\" does not exist\nLINE 1: ...id\", \"name\", \"deleted_time\", \"original_location\", \"file_id\")...\n                                                             ^",
            "Code": "42703",
            "Trace": [{
                "file": "/var/www/html/nextcloud/3rdparty/doctrine/dbal/lib/Doctrine/DBAL/Driver/PDOStatement.php",
                "line": 127,
                "function": "execute",
                "class": "PDOStatement",
                "type": "->"
            }, {
                "file": "/var/www/html/nextcloud/3rdparty/doctrine/dbal/lib/Doctrine/DBAL/Connection.php",
                "line": 1062,
                "function": "execute",
                "class": "Doctrine\\DBAL\\Driver\\PDOStatement",
                "type": "->"
            }, {
                "file": "/var/www/html/nextcloud/lib/private/DB/Connection.php",
                "line": 222,
                "function": "executeUpdate",
                "class": "Doctrine\\DBAL\\Connection",
                "type": "->"
            }, {
                "file": "/var/www/html/nextcloud/3rdparty/doctrine/dbal/lib/Doctrine/DBAL/Query/QueryBuilder.php",
                "line": 209,
                "function": "executeUpdate",
                "class": "OC\\DB\\Connection",
                "type": "->"
            }, {
                "file": "/var/www/html/nextcloud/lib/private/DB/QueryBuilder/QueryBuilder.php",
                "line": 217,
                "function": "execute",
                "class": "Doctrine\\DBAL\\Query\\QueryBuilder",
                "type": "->"
            }, {
                "file": "/var/www/html/nextcloud/apps/groupfolders/lib/Trash/TrashManager.php",
                "line": 53,
                "function": "execute",
                "class": "OC\\DB\\QueryBuilder\\QueryBuilder",
                "type": "->"
            }, {
                "file": "/var/www/html/nextcloud/apps/groupfolders/lib/Trash/TrashBackend.php",
                "line": 180,
                "function": "addTrashItem",
                "class": "OCA\\GroupFolders\\Trash\\TrashManager",
                "type": "->"
            }, {
                "file": "/var/www/html/nextcloud/apps/files_trashbin/lib/Trash/TrashManager.php",
                "line": 103,
                "function": "moveToTrash",
                "class": "OCA\\GroupFolders\\Trash\\TrashBackend",
                "type": "->"
            }, {
                "file": "/var/www/html/nextcloud/apps/files_trashbin/lib/Storage.php",
                "line": 192,
                "function": "moveToTrash",
                "class": "OCA\\Files_Trashbin\\Trash\\TrashManager",
                "type": "->"
            }, {
                "file": "/var/www/html/nextcloud/apps/files_trashbin/lib/Storage.php",
                "line": 99,
                "function": "doDelete",
                "class": "OCA\\Files_Trashbin\\Storage",
                "type": "->"
            }, {
                "file": "/var/www/html/nextcloud/lib/private/Files/View.php",
                "line": 1167,
                "function": "unlink",
                "class": "OCA\\Files_Trashbin\\Storage",
                "type": "->"
            }, {
                "file": "/var/www/html/nextcloud/lib/private/Files/View.php",
                "line": 724,
                "function": "basicOperation",
                "class": "OC\\Files\\View",
                "type": "->"
            }, {
                "file": "/var/www/html/nextcloud/apps/dav/lib/Connector/Sabre/File.php",
                "line": 466,
                "function": "unlink",
                "class": "OC\\Files\\View",
                "type": "->"
            }, {
                "file": "/var/www/html/nextcloud/3rdparty/sabre/dav/lib/DAV/Tree.php",
                "line": 183,
                "function": "delete",
                "class": "OCA\\DAV\\Connector\\Sabre\\File",
                "type": "->"
            }, {
                "file": "/var/www/html/nextcloud/3rdparty/sabre/dav/lib/DAV/CorePlugin.php",
                "line": 295,
                "function": "delete",
                "class": "Sabre\\DAV\\Tree",
                "type": "->"
            }, {
                "file": "/var/www/html/nextcloud/3rdparty/sabre/event/lib/WildcardEmitterTrait.php",
                "line": 89,
                "function": "httpDelete",
                "class": "Sabre\\DAV\\CorePlugin",
                "type": "->"
            }, {
                "file": "/var/www/html/nextcloud/3rdparty/sabre/dav/lib/DAV/Server.php",
                "line": 474,
                "function": "emit",
                "class": "Sabre\\DAV\\Server",
                "type": "->"
            }, {
                "file": "/var/www/html/nextcloud/3rdparty/sabre/dav/lib/DAV/Server.php",
                "line": 251,
                "function": "invokeMethod",
                "class": "Sabre\\DAV\\Server",
                "type": "->"
            }, {
                "file": "/var/www/html/nextcloud/3rdparty/sabre/dav/lib/DAV/Server.php",
                "line": 319,
                "function": "start",
                "class": "Sabre\\DAV\\Server",
                "type": "->"
            }, {
                "file": "/var/www/html/nextcloud/apps/dav/lib/Server.php",
                "line": 332,
                "function": "exec",
                "class": "Sabre\\DAV\\Server",
                "type": "->"
            }, {
                "file": "/var/www/html/nextcloud/apps/dav/appinfo/v2/remote.php",
                "line": 35,
                "function": "exec",
                "class": "OCA\\DAV\\Server",
                "type": "->"
            }, {
                "file": "/var/www/html/nextcloud/remote.php",
                "line": 167,
                "args": ["/var/www/html/nextcloud/apps/dav/appinfo/v2/remote.php"],
                "function": "require_once"
            }],
            "File": "/var/www/html/nextcloud/3rdparty/doctrine/dbal/lib/Doctrine/DBAL/Driver/PDOStatement.php",
            "Line": 127
        }
    },
    "CustomMessage": "--"
},
"userAgent": "Mozilla/5.0 (Linux) mirall/3.0.3git (build 3795) (Nextcloud)",
"version": "20.0.2.2",
"id": "5fc22e3827fc9"
}

Aaargh, this went away, and now it’s happening again. And not a peep out of any savvy Nextcloud pro here. What does this mean? I think what I did to relieve myself of this last time was copy said folders away somewhere, remove them from NextCloud altogether as bets possible, then copy them back. let’s see if it works this time.

The sad irony being that Googling this error message I get one hit, my unanswered question! I seem to recall a Google competition to formulate a query that returns precisely one hit! I could have won it now!

And it happening again. What gives? How can the file_id of of relation “oc_group_folders_trash” be missing? What is broken? And why does no-one else see this problem?

For now I give up, and I’m taking a risk and did this:

ALTER TABLE public.oc_group_folders_trash
ADD COLUMN file_id bigint;

and see what happens. Fiddling with schemas is dangerous. But we shall see. it’s very clearly a nextcloud bug as something is trying an invalid query.

So I also too a look at the stack trace and the culprit is the groupfolders in apps/groupfolders/lib/Trash/TrashManager.php wherein a query is constructed with:

	public function addTrashItem(int $folderId, string $name, int $deletedTime, string $originalLocation, int $fileId): void {
		$query = $this->connection->getQueryBuilder();
		$query->insert('group_folders_trash')
			->values([
				'folder_id' => $query->createNamedParameter($folderId, IQueryBuilder::PARAM_INT),
				'name' => $query->createNamedParameter($name),
				'deleted_time' => $query->createNamedParameter($deletedTime, IQueryBuilder::PARAM_INT),
				'original_location' => $query->createNamedParameter($originalLocation),
				'file_id' => $query->createNamedParameter($fileId, IQueryBuilder::PARAM_INT)
			]);
		$query->execute();
	}

and file_id is simply not a column in the table. Grrr. So I added it to the table. Fingers crossed.