passbolt / passbolt_api

Passbolt Community Edition (CE) API. The JSON API for the open source password manager for teams!
https://passbolt.com
GNU Affero General Public License v3.0
4.48k stars 300 forks source link

SQL error on creating folders when using PostgreSQL database #508

Closed chris968 closed 1 day ago

chris968 commented 3 months ago

Platform info:

How to reproduce:

Create a folder through the web GUI or launching cake passbolt cleanup command. The web GUI throw an error 500 but the application log show the following entry:

2024-03-14 10:17:03 error: [PDOException] SQLSTATE[23502]: Not null violation: 7 ERROR:  null value in column "id" of relation "folders" violates not-null constraint
DETAIL:  Failing row contains (null, test, 2024-03-14 11:17:03.433147+01, 2024-03-14 11:17:03.433182+01, 0b2ad4a5-c7d1-4c1c-95ef-ede2e477f87a, 0b2ad4a5-c7d1-4c1c-95ef-ede2e477f87a). in /var/www/passbolt/vendor/cakephp/cakephp/src/Database/Statement/StatementDecorator.php on line 180
Request URL: /folders.json?api-version=v2&contain%5Bpermission%5D=1
Client IP: 192.168.122.4

The cake passbolt cleanup command show another error message related to the folders table:

2024-03-14 10:22:09 error: [PDOException] SQLSTATE[42883]: Undefined function: 7 ERROR:  operator does not exist: character = uuid
LINE 1: ..." LEFT JOIN "folders" "Folders" ON "Folders"."id" = "Permiss...
                                                             ^
HINT:  No operator matches the given name and argument types. You might need to add explicit type casts. in /var/www/passbolt/vendor/cakephp/cakephp/src/Database/Statement/StatementDecorator.php on line 180

We reproduce the issue on two distinct setups, the database have been migrated from a working MySQL one.

stripthis commented 3 months ago

Thanks for the report @chris968, we'll look into it.

chris968 commented 3 months ago

I just realized that this have an impact on creating new passwords.

Screenshot from 2024-03-14 13-46-27

chris968 commented 3 months ago

My current workaround is to disable the "folders" plugin:


<?php

return [
  'passbolt' => [
    'plugins' => [
      'folders' => [
        'enabled' => false,
      ],
    ],
  ],
];
``
pabloelcolombiano commented 3 months ago

Hi @chris968 ,

it could be that during the migration from MySQL to Postgres, some folders got their id set to null.

  1. Could you run this query in your postgres client, to see if this is the case? select * from folders where "id" = null;

  2. Also this query could be interesting: select column_name, data_type, character_maximum_length, column_default, is_nullable from INFORMATION_SCHEMA.COLUMNS where table_name = 'folders';

chris968 commented 3 months ago

@pabloelcolombiano of course I can run both commands but we have no folders in our setup:

passbolt-db=>  select * from folders where "id" = null;
 id | name | created | modified | created_by | modified_by
----+------+---------+----------+------------+-------------
(0 rows)

passbolt-db=> select column_name, data_type, character_maximum_length, column_default, is_nullable from INFORMATION_SCHEMA.COLUMNS where table_name = 'folders';
 column_name |        data_type         | character_maximum_length | column_default | is_nullable
-------------+--------------------------+--------------------------+----------------+-------------
 created     | timestamp with time zone |                          |                | NO
 modified    | timestamp with time zone |                          |                | NO
 id          | character                |                       36 |                | NO
 name        | character varying        |                      256 |                | NO
 created_by  | character                |                       36 |                | NO
 modified_by | character                |                       36 |                | NO
(6 rows)
jsm222 commented 3 months ago

operator does not exist: character = uuid so the folders.id might still be of character type and not of the postgres uuid type @pabloelcolombiano

pabloelcolombiano commented 1 month ago

Hi @chris968 ,

thank you for the feedback, and sorry for the delay on the response. As @jsm222 mentions, we should channge the column type to uuid. It looks like one migration was not run properly. What is the output of this command?

SELECT * FROM "phinxlog" WHERE migration_name IN ('V3120MigrateASCIIFieldsEncodingFolders');
DELETE FROM "phinxlog" WHERE migration_name = 'V3120MigrateASCIIFieldsEncodingFolders';

and run the migrations again

bin/cake passbolt migrate

and provide us the output of the command.

Once this is done, it would be interesting to check this command again:

select column_name, data_type, character_maximum_length, column_default, is_nullable from INFORMATION_SCHEMA.COLUMNS where table_name = 'folders';
pabloelcolombiano commented 1 day ago

Closing this for now.