From ecc58cb48294a647f042cd00f7c3fe43b203ac95 Mon Sep 17 00:00:00 2001 From: Thibault Libioulle Date: Mon, 20 Mar 2023 16:41:44 +0000 Subject: [PATCH] [FIX] project: fix tag name search with none project in context This commit fixes the name_search traceback on project tags when the `project_id` in context is set to `False`. Prior to commit odoo/odoo@05855b6b this check was still relevant since the implementation used the ORM search method. Since this commit, project_id must be an integer to be used in the SQL query. Steps to reproduce: - Open Project menu; - Go to My Tasks menu; - Create a new task; - Open task; - Click on Tags field. Current Behavior: ``` File "/home/src/odoo/odoo/models.py", line 1605, in name_search ids = self._name_search(name, args, operator, limit=limit) File "/home/src/odoo/addons/project/models/project.py", line 2756, in _name_search self.env.cr.execute(query, params) File "/home/src/odoo/odoo/sql_db.py", line 313, in execute res = self._obj.execute(query, params) psycopg2.errors.UndefinedFunction: operator does not exist: integer = boolean LINE 9: ON task.project_id = false ^ HINT: No operator matches the given name and argument types. You might need to add explicit type casts. ``` Expected Behavior: - No traceback and standard name_search behavior. closes odoo/odoo#116006 X-original-commit: f21bd6f47a75f5d6cbd442f30ef7df221e6fec7d Signed-off-by: Xavier Bol (xbo) --- addons/project/models/project.py | 2 +- addons/project/tests/test_project_flow.py | 8 ++++++++ 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/addons/project/models/project.py b/addons/project/models/project.py index edec05a4b62..402a7110038 100644 --- a/addons/project/models/project.py +++ b/addons/project/models/project.py @@ -2653,7 +2653,7 @@ class ProjectTags(models.Model): @api.model def _name_search(self, name, domain=None, operator='ilike', limit=None, order=None, name_get_uid=None): - if 'project_id' in self.env.context and operator == 'ilike': + if self.env.context.get('project_id') and operator == 'ilike': # `domain` has the form of the default filter ['!', ['id', 'in', ]] # passed to exclude already selected tags -> exclude them in our query too excluded_ids = list(domain[1][2]) \ diff --git a/addons/project/tests/test_project_flow.py b/addons/project/tests/test_project_flow.py index e8b1d171f24..ba00a0b9b41 100644 --- a/addons/project/tests/test_project_flow.py +++ b/addons/project/tests/test_project_flow.py @@ -438,3 +438,11 @@ class TestProjectFlow(TestProjectCommon, MailCommon): self.assertEqual(len(project_A.message_ids), init_nb_log + 2, "should have 2 new messages: one for tracking, one for template") + + def test_private_task_search_tag(self): + task = self.env['project.task'].create({ + 'name': 'Test Private Task', + }) + # Tag name_search should not raise Error if project_id is False + task.tag_ids.with_context(project_id=task.project_id.id).name_search( + args=["!", ["id", "in", []]])