Skip to Content
Menu
This question has been flagged
2 Replies
1095 Views

Hi everyone,

I'm using Odoo.sh to build my custom module, but I've encountered an issue with tests.

At first, I thought the problem was with my code. However, after completely removing everything and restarting from a fully empty branch (0 commits), I noticed that the following command works perfectly on a blank database:

odoo-bin --test-enable --stop-after-init --log-level=test

But if I install the Contacts module (via the app installation interface) and rerun the same test command:

odoo-bin --test-enable --stop-after-init --log-level=test

I immediately get many errors like this:

odoo.sql_db: bad query: b'INSERT INTO "res_users" ("active", "company_id", "create_date", "create_uid", "login", "partner_id", "write_date", "write_uid") VALUES (true, 1, '2025-02-15 00:04:13.125900', 1, 'u1', 578, '2025-02-15 00:04:13.125900', 1) RETURNING "id"' ERROR: null value in column "notification_type" of relation "res_users" violates not-null constraint DETAIL: Failing row contains (58, 1, 578, t, 2025-02-15 00:04:13.1259, u1, null, null, 1, 1, null, null, 2025-02-15 00:04:13.1259, null, null, null, null, null).

Example traceback:

odoo.addons.base.tests.test_base: ERROR: TestGroups.test_remove_groups Traceback (most recent call last): File "/home/odoo/src/odoo/odoo/addons/base/tests/test_base.py", line 209, in test_remove_groups u1 = self.env['res.users'].create({'login': 'u1', 'name': 'U1'}) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "<decorator-gen-32>", line 2, in create File "/home/odoo/src/odoo/odoo/api.py", line 479, in _model_create_multi return create(self, [arg]) ^^^^^^^^^^^^^^^^^^^ File "/home/odoo/src/odoo/odoo/addons/base/models/res_users.py", line 1901, in create users = super(UsersView, self).create(new_vals_list) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "<decorator-gen-30>", line 2, in create File "/home/odoo/src/odoo/odoo/api.py", line 480, in _model_create_multi return create(self, arg) ^^^^^^^^^^^^^^^^^ File "/home/odoo/src/odoo/odoo/addons/base/models/res_users.py", line 1602, in create return super(UsersImplied, self).create(vals_list) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "<decorator-gen-28>", line 2, in create File "/home/odoo/src/odoo/odoo/api.py", line 480, in _model_create_multi return create(self, arg) ^^^^^^^^^^^^^^^^^ File "/home/odoo/src/odoo/odoo/addons/base/models/res_users.py", line 706, in create users = super(Users, self).create(vals_list) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "<decorator-gen-0>", line 2, in create File "/home/odoo/src/odoo/odoo/api.py", line 480, in _model_create_multi return create(self, arg) ^^^^^^^^^^^^^^^^^ File "/home/odoo/src/odoo/odoo/models.py", line 4975, in create records = self._create(data_list) ^^^^^^^^^^^^^^^^^^^^^^^ File "/home/odoo/src/odoo/odoo/models.py", line 5159, in _create cr.execute(SQL( File "/home/odoo/src/odoo/odoo/sql_db.py", line 354, in execute res = self._obj.execute(query, params) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ psycopg2.errors.NotNullViolation: null value in column "notification_type" of relation "res_users" violates not-null constraint DETAIL: Failing row contains (58, 1, 578, t, 2025-02-15 00:04:13.1259, u1, null, null, 1, 1, null, null, 2025-02-15 00:04:13.1259, null, null, null, null, null).

The error seems to be caused by a missing value in the notification_type column when inserting a new user.

Is there an issue with the Contacts module, or am I doing something wrong?

I'm using Odoo 18 on Odoo.sh with the latest revision.

Thanks in advance for your help!


Avatar
Discard
Best Answer

Hi,

The issue you're encountering is related to the notification_type field in the res.users model, which is a required field (not null) in Odoo. When creating a new user, this field must be provided, but it seems that the test or the Contacts module is not setting it correctly.


Set a Default Value for notification_type

notification_type = fields.Selection(

        selection=[

            ('email', 'Handle by Emails'),

            ('inbox', 'Handle in Odoo'),

        ],

        default='email',  # Set a default value

        required=True,

    )

Update Existing Users

UPDATE res_users SET notification_type = 'email' WHERE notification_type IS NULL;


Hope it helps

Avatar
Discard
Best Answer

Update all modules once then try it again.

Avatar
Discard
Author

Thank you for your answer but it is still the same : I cliked update al modules from the online editor and then launched the test again and I still have the same error

Related Posts Replies Views Activity
0
Nov 20
57
1
Mar 24
1608
2
Mar 24
1605
1
Apr 25
2196
2
Oct 23
2798