We are currently solving the following issue within our repository. Here is the issue text:
--- BEGIN ISSUE ---
base_name_search_improved  - Portal Access Managment
@dreispt 
This ocurrs in when click on customer --> More --> Portal Access Managment.

> Traceback (most recent call last):
>   File "/opt/odoov1/OCB/openerp/http.py", line 539, in _handle_exception
>     return super(JsonRequest, self)._handle_exception(exception)
>   File "/opt/odoov1/OCB/openerp/http.py", line 576, in dispatch
>     result = self._call_function(*_self.params)
>   File "/opt/odoov1/OCB/openerp/http.py", line 312, in _call_function
>     return checked_call(self.db, *args, *_kwargs)
>   File "/opt/odoov1/OCB/openerp/service/model.py", line 118, in wrapper
>     return f(dbname, _args, *_kwargs)
>   File "/opt/odoov1/OCB/openerp/http.py", line 309, in checked_call
>     return self.endpoint(_a, *_kw)
>   File "/opt/odoov1/OCB/openerp/http.py", line 805, in __call__
>     return self.method(_args, *_kw)
>   File "/opt/odoov1/OCB/openerp/http.py", line 405, in response_wrap
>     response = f(_args, *_kw)
>   File "/opt/odoov1/OCB/addons/web/controllers/main.py", line 944, in call_kw
>     return self._call_kw(model, method, args, kwargs)
>   File "/opt/odoov1/OCB/addons/web/controllers/main.py", line 936, in _call_kw
>     return getattr(request.registry.get(model), method)(request.cr, request.uid, _args, *_kwargs)
>   File "/opt/odoov1/OCB/openerp/api.py", line 268, in wrapper
>     return old_api(self, _args, *_kwargs)
>   File "/opt/odoov1/OCB/openerp/api.py", line 372, in old_api
>     result = method(recs, _args, *_kwargs)
>   File "/opt/odoov1/extra-addons/base_name_search_improved/models/ir_model.py", line 61, in name_search
>     res = _extend_name_results(self, domain, res, limit)
>   File "/opt/odoov1/extra-addons/base_name_search_improved/models/ir_model.py", line 27, in _extend_name_results
>     recs = self.search(domain, limit=limit - result_count)
>   File "/opt/odoov1/OCB/openerp/api.py", line 266, in wrapper
>     return new_api(self, _args, *_kwargs)
>   File "/opt/odoov1/OCB/openerp/api.py", line 508, in new_api
>     result = method(self._model, cr, uid, _args, *_old_kwargs)
>   File "/opt/odoov1/OCB/openerp/addons/base/res/res_users.py", line 121, in search
>     return super(res_groups, self).search(cr, uid, args, offset, limit, order, context, count)
>   File "/opt/odoov1/OCB/openerp/api.py", line 268, in wrapper
>     return old_api(self, _args, *_kwargs)
>   File "/opt/odoov1/OCB/openerp/models.py", line 1646, in search
>     return self._search(cr, user, args, offset=offset, limit=limit, order=order, context=context, count=count)
>   File "/opt/odoov1/OCB/openerp/api.py", line 268, in wrapper
>     return old_api(self, _args, *_kwargs)
>   File "/opt/odoov1/OCB/openerp/models.py", line 4673, in _search
>     query = self._where_calc(cr, user, args, context=context)
>   File "/opt/odoov1/OCB/openerp/api.py", line 268, in wrapper
>     return old_api(self, _args, *_kwargs)
>   File "/opt/odoov1/OCB/openerp/models.py", line 4484, in _where_calc
>     e = expression.expression(cr, user, domain, self, context)
>   File "/opt/odoov1/OCB/openerp/osv/expression.py", line 662, in __init__
>     self.parse(cr, uid, context=context)
>   File "/opt/odoov1/OCB/openerp/osv/expression.py", line 921, in parse
>     fct_domain = column.search(cr, uid, model, left, [leaf.leaf], context=context)
>   File "/opt/odoov1/OCB/openerp/osv/fields.py", line 1423, in search
>     return self._fnct_search(obj, cr, uid, obj, name, args, context=context)
>   File "/opt/odoov1/OCB/openerp/addons/base/res/res_users.py", line 80, in _search_group
>     group_name = values.pop().strip()
> IndexError: pop from empty list


--- END ISSUE ---

Below are some code segments, each from a relevant file. One or more of these files may contain bugs.
--- BEGIN FILES ---
Path: `base_name_search_improved/models/ir_model.py`
Content:
```
1 # -*- coding: utf-8 -*-
2 # © 2016 Daniel Reis
3 # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
4 
5 from openerp import models, fields, api
6 from openerp import SUPERUSER_ID
7 from openerp import tools
8 
9 
10 # Extended name search is only used on some operators
11 ALLOWED_OPS = set(['ilike', 'like'])
12 
13 
14 @tools.ormcache(skiparg=0)
15 def _get_rec_names(self):
16     model = self.env['ir.model'].search(
17         [('model', '=', str(self._model))])
18     rec_name = [self._rec_name] or []
19     other_names = model.name_search_ids.mapped('name')
20     return rec_name + other_names
21 
22 
23 def _extend_name_results(self, domain, results, limit):
24     result_count = len(results)
25     if result_count < limit:
26         domain += [('id', 'not in', [x[0] for x in results])]
27         recs = self.search(domain, limit=limit - result_count)
28         results.extend(recs.name_get())
29     return results
30 
31 
32 class ModelExtended(models.Model):
33     _inherit = 'ir.model'
34 
35     name_search_ids = fields.Many2many(
36         'ir.model.fields',
37         string='Name Search Fields')
38 
39     def _register_hook(self, cr, ids=None):
40 
41         def make_name_search():
42 
43             @api.model
44             def name_search(self, name='', args=None,
45                             operator='ilike', limit=100):
46                 # Perform standard name search
47                 res = name_search.origin(
48                     self, name=name, args=args, operator=operator, limit=limit)
49                 enabled = self.env.context.get('name_search_extended', True)
50                 # Perform extended name search
51                 if enabled and operator in ALLOWED_OPS:
52                     # Support a list of fields to search on
53                     all_names = _get_rec_names(self)
54                     # Try regular search on each additional search field
55                     for rec_name in all_names[1:]:
56                         domain = [(rec_name, operator, name)]
57                         res = _extend_name_results(self, domain, res, limit)
58                     # Try ordered word search on each of the search fields
59                     for rec_name in all_names:
60                         domain = [(rec_name, operator, name.replace(' ', '%'))]
61                         res = _extend_name_results(self, domain, res, limit)
62                     # Try unordered word search on each of the search fields
63                     for rec_name in all_names:
64                         domain = [(rec_name, operator, x)
65                                   for x in name.split() if x]
66                         res = _extend_name_results(self, domain, res, limit)
67                 return res
68             return name_search
69 
70         if ids is None:
71             ids = self.search(cr, SUPERUSER_ID, [])
72         for model in self.browse(cr, SUPERUSER_ID, ids):
73             Model = self.pool.get(model.model)
74             if Model:
75                 Model._patch_method('name_search', make_name_search())
76         return super(ModelExtended, self)._register_hook(cr)
77
```
--- END FILES ---

Please first localize the bug based on the issue statement, and then generate a patch according to the `git diff` format fenced by three backticks.

Here is an example:

```diff
diff --git a/examples/server_async.py b/examples/server_async.py
--- a/examples/server_async.py
+++ b/examples/server_async.py
@@ -313,4 +313,4 @@
 
 
 if __name__ == "__main__":
-    asyncio.run(run_async_server("."), debug=True)
+    asyncio.run(run_async_server(), debug=True)
diff --git a/examples/server_sync.py b/examples/server_sync.py
--- a/examples/server_sync.py
+++ b/examples/server_sync.py
@@ -313,5 +313,5 @@
 
 
 if __name__ == "__main__":
-    server = run_sync_server(".")
+    server = run_sync_server()
     server.shutdown()

```

diff --git a/base_name_search_improved/models/ir_model.py b/base_name_search_improved/models/ir_model.py
--- a/base_name_search_improved/models/ir_model.py
+++ b/base_name_search_improved/models/ir_model.py
@@ -13,6 +13,7 @@
 
 @tools.ormcache(skiparg=0)
 def _get_rec_names(self):
+    "List of fields to search into"
     model = self.env['ir.model'].search(
         [('model', '=', str(self._model))])
     rec_name = [self._rec_name] or []
@@ -48,22 +49,28 @@
                     self, name=name, args=args, operator=operator, limit=limit)
                 enabled = self.env.context.get('name_search_extended', True)
                 # Perform extended name search
-                if enabled and operator in ALLOWED_OPS:
+                # Note: Empty name causes error on
+                #       Customer->More->Portal Access Management
+                if name and enabled and operator in ALLOWED_OPS:
                     # Support a list of fields to search on
                     all_names = _get_rec_names(self)
+                    base_domain = args or []
                     # Try regular search on each additional search field
                     for rec_name in all_names[1:]:
                         domain = [(rec_name, operator, name)]
-                        res = _extend_name_results(self, domain, res, limit)
+                        res = _extend_name_results(
+                            self, base_domain + domain, res, limit)
                     # Try ordered word search on each of the search fields
                     for rec_name in all_names:
                         domain = [(rec_name, operator, name.replace(' ', '%'))]
-                        res = _extend_name_results(self, domain, res, limit)
+                        res = _extend_name_results(
+                            self, base_domain + domain, res, limit)
                     # Try unordered word search on each of the search fields
                     for rec_name in all_names:
                         domain = [(rec_name, operator, x)
                                   for x in name.split() if x]
-                        res = _extend_name_results(self, domain, res, limit)
+                        res = _extend_name_results(
+                            self, base_domain + domain, res, limit)
                 return res
             return name_search

{"golden_diff": "diff --git a/base_name_search_improved/models/ir_model.py b/base_name_search_improved/models/ir_model.py\n--- a/base_name_search_improved/models/ir_model.py\n+++ b/base_name_search_improved/models/ir_model.py\n@@ -13,6 +13,7 @@\n \n @tools.ormcache(skiparg=0)\n def _get_rec_names(self):\n+    \"List of fields to search into\"\n     model = self.env['ir.model'].search(\n         [('model', '=', str(self._model))])\n     rec_name = [self._rec_name] or []\n@@ -48,22 +49,28 @@\n                     self, name=name, args=args, operator=operator, limit=limit)\n                 enabled = self.env.context.get('name_search_extended', True)\n                 # Perform extended name search\n-                if enabled and operator in ALLOWED_OPS:\n+                # Note: Empty name causes error on\n+                #       Customer->More->Portal Access Management\n+                if name and enabled and operator in ALLOWED_OPS:\n                     # Support a list of fields to search on\n                     all_names = _get_rec_names(self)\n+                    base_domain = args or []\n                     # Try regular search on each additional search field\n                     for rec_name in all_names[1:]:\n                         domain = [(rec_name, operator, name)]\n-                        res = _extend_name_results(self, domain, res, limit)\n+                        res = _extend_name_results(\n+                            self, base_domain + domain, res, limit)\n                     # Try ordered word search on each of the search fields\n                     for rec_name in all_names:\n                         domain = [(rec_name, operator, name.replace(' ', '%'))]\n-                        res = _extend_name_results(self, domain, res, limit)\n+                        res = _extend_name_results(\n+                            self, base_domain + domain, res, limit)\n                     # Try unordered word search on each of the search fields\n                     for rec_name in all_names:\n                         domain = [(rec_name, operator, x)\n                                   for x in name.split() if x]\n-                        res = _extend_name_results(self, domain, res, limit)\n+                        res = _extend_name_results(\n+                            self, base_domain + domain, res, limit)\n                 return res\n             return name_search\n", "issue": "base_name_search_improved  - Portal Access Managment\n@dreispt \nThis ocurrs in when click on customer --> More --> Portal Access Managment.\n\n> Traceback (most recent call last):\n>   File \"/opt/odoov1/OCB/openerp/http.py\", line 539, in _handle_exception\n>     return super(JsonRequest, self)._handle_exception(exception)\n>   File \"/opt/odoov1/OCB/openerp/http.py\", line 576, in dispatch\n>     result = self._call_function(*_self.params)\n>   File \"/opt/odoov1/OCB/openerp/http.py\", line 312, in _call_function\n>     return checked_call(self.db, *args, *_kwargs)\n>   File \"/opt/odoov1/OCB/openerp/service/model.py\", line 118, in wrapper\n>     return f(dbname, _args, *_kwargs)\n>   File \"/opt/odoov1/OCB/openerp/http.py\", line 309, in checked_call\n>     return self.endpoint(_a, *_kw)\n>   File \"/opt/odoov1/OCB/openerp/http.py\", line 805, in __call__\n>     return self.method(_args, *_kw)\n>   File \"/opt/odoov1/OCB/openerp/http.py\", line 405, in response_wrap\n>     response = f(_args, *_kw)\n>   File \"/opt/odoov1/OCB/addons/web/controllers/main.py\", line 944, in call_kw\n>     return self._call_kw(model, method, args, kwargs)\n>   File \"/opt/odoov1/OCB/addons/web/controllers/main.py\", line 936, in _call_kw\n>     return getattr(request.registry.get(model), method)(request.cr, request.uid, _args, *_kwargs)\n>   File \"/opt/odoov1/OCB/openerp/api.py\", line 268, in wrapper\n>     return old_api(self, _args, *_kwargs)\n>   File \"/opt/odoov1/OCB/openerp/api.py\", line 372, in old_api\n>     result = method(recs, _args, *_kwargs)\n>   File \"/opt/odoov1/extra-addons/base_name_search_improved/models/ir_model.py\", line 61, in name_search\n>     res = _extend_name_results(self, domain, res, limit)\n>   File \"/opt/odoov1/extra-addons/base_name_search_improved/models/ir_model.py\", line 27, in _extend_name_results\n>     recs = self.search(domain, limit=limit - result_count)\n>   File \"/opt/odoov1/OCB/openerp/api.py\", line 266, in wrapper\n>     return new_api(self, _args, *_kwargs)\n>   File \"/opt/odoov1/OCB/openerp/api.py\", line 508, in new_api\n>     result = method(self._model, cr, uid, _args, *_old_kwargs)\n>   File \"/opt/odoov1/OCB/openerp/addons/base/res/res_users.py\", line 121, in search\n>     return super(res_groups, self).search(cr, uid, args, offset, limit, order, context, count)\n>   File \"/opt/odoov1/OCB/openerp/api.py\", line 268, in wrapper\n>     return old_api(self, _args, *_kwargs)\n>   File \"/opt/odoov1/OCB/openerp/models.py\", line 1646, in search\n>     return self._search(cr, user, args, offset=offset, limit=limit, order=order, context=context, count=count)\n>   File \"/opt/odoov1/OCB/openerp/api.py\", line 268, in wrapper\n>     return old_api(self, _args, *_kwargs)\n>   File \"/opt/odoov1/OCB/openerp/models.py\", line 4673, in _search\n>     query = self._where_calc(cr, user, args, context=context)\n>   File \"/opt/odoov1/OCB/openerp/api.py\", line 268, in wrapper\n>     return old_api(self, _args, *_kwargs)\n>   File \"/opt/odoov1/OCB/openerp/models.py\", line 4484, in _where_calc\n>     e = expression.expression(cr, user, domain, self, context)\n>   File \"/opt/odoov1/OCB/openerp/osv/expression.py\", line 662, in __init__\n>     self.parse(cr, uid, context=context)\n>   File \"/opt/odoov1/OCB/openerp/osv/expression.py\", line 921, in parse\n>     fct_domain = column.search(cr, uid, model, left, [leaf.leaf], context=context)\n>   File \"/opt/odoov1/OCB/openerp/osv/fields.py\", line 1423, in search\n>     return self._fnct_search(obj, cr, uid, obj, name, args, context=context)\n>   File \"/opt/odoov1/OCB/openerp/addons/base/res/res_users.py\", line 80, in _search_group\n>     group_name = values.pop().strip()\n> IndexError: pop from empty list\n\n", "before_files": [{"content": "# -*- coding: utf-8 -*-\n# \u00a9 2016 Daniel Reis\n# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).\n\nfrom openerp import models, fields, api\nfrom openerp import SUPERUSER_ID\nfrom openerp import tools\n\n\n# Extended name search is only used on some operators\nALLOWED_OPS = set(['ilike', 'like'])\n\n\n@tools.ormcache(skiparg=0)\ndef _get_rec_names(self):\n    model = self.env['ir.model'].search(\n        [('model', '=', str(self._model))])\n    rec_name = [self._rec_name] or []\n    other_names = model.name_search_ids.mapped('name')\n    return rec_name + other_names\n\n\ndef _extend_name_results(self, domain, results, limit):\n    result_count = len(results)\n    if result_count < limit:\n        domain += [('id', 'not in', [x[0] for x in results])]\n        recs = self.search(domain, limit=limit - result_count)\n        results.extend(recs.name_get())\n    return results\n\n\nclass ModelExtended(models.Model):\n    _inherit = 'ir.model'\n\n    name_search_ids = fields.Many2many(\n        'ir.model.fields',\n        string='Name Search Fields')\n\n    def _register_hook(self, cr, ids=None):\n\n        def make_name_search():\n\n            @api.model\n            def name_search(self, name='', args=None,\n                            operator='ilike', limit=100):\n                # Perform standard name search\n                res = name_search.origin(\n                    self, name=name, args=args, operator=operator, limit=limit)\n                enabled = self.env.context.get('name_search_extended', True)\n                # Perform extended name search\n                if enabled and operator in ALLOWED_OPS:\n                    # Support a list of fields to search on\n                    all_names = _get_rec_names(self)\n                    # Try regular search on each additional search field\n                    for rec_name in all_names[1:]:\n                        domain = [(rec_name, operator, name)]\n                        res = _extend_name_results(self, domain, res, limit)\n                    # Try ordered word search on each of the search fields\n                    for rec_name in all_names:\n                        domain = [(rec_name, operator, name.replace(' ', '%'))]\n                        res = _extend_name_results(self, domain, res, limit)\n                    # Try unordered word search on each of the search fields\n                    for rec_name in all_names:\n                        domain = [(rec_name, operator, x)\n                                  for x in name.split() if x]\n                        res = _extend_name_results(self, domain, res, limit)\n                return res\n            return name_search\n\n        if ids is None:\n            ids = self.search(cr, SUPERUSER_ID, [])\n        for model in self.browse(cr, SUPERUSER_ID, ids):\n            Model = self.pool.get(model.model)\n            if Model:\n                Model._patch_method('name_search', make_name_search())\n        return super(ModelExtended, self)._register_hook(cr)\n", "path": "base_name_search_improved/models/ir_model.py"}], "after_files": [{"content": "# -*- coding: utf-8 -*-\n# \u00a9 2016 Daniel Reis\n# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).\n\nfrom openerp import models, fields, api\nfrom openerp import SUPERUSER_ID\nfrom openerp import tools\n\n\n# Extended name search is only used on some operators\nALLOWED_OPS = set(['ilike', 'like'])\n\n\n@tools.ormcache(skiparg=0)\ndef _get_rec_names(self):\n    \"List of fields to search into\"\n    model = self.env['ir.model'].search(\n        [('model', '=', str(self._model))])\n    rec_name = [self._rec_name] or []\n    other_names = model.name_search_ids.mapped('name')\n    return rec_name + other_names\n\n\ndef _extend_name_results(self, domain, results, limit):\n    result_count = len(results)\n    if result_count < limit:\n        domain += [('id', 'not in', [x[0] for x in results])]\n        recs = self.search(domain, limit=limit - result_count)\n        results.extend(recs.name_get())\n    return results\n\n\nclass ModelExtended(models.Model):\n    _inherit = 'ir.model'\n\n    name_search_ids = fields.Many2many(\n        'ir.model.fields',\n        string='Name Search Fields')\n\n    def _register_hook(self, cr, ids=None):\n\n        def make_name_search():\n\n            @api.model\n            def name_search(self, name='', args=None,\n                            operator='ilike', limit=100):\n                # Perform standard name search\n                res = name_search.origin(\n                    self, name=name, args=args, operator=operator, limit=limit)\n                enabled = self.env.context.get('name_search_extended', True)\n                # Perform extended name search\n                # Note: Empty name causes error on\n                #       Customer->More->Portal Access Management\n                if name and enabled and operator in ALLOWED_OPS:\n                    # Support a list of fields to search on\n                    all_names = _get_rec_names(self)\n                    base_domain = args or []\n                    # Try regular search on each additional search field\n                    for rec_name in all_names[1:]:\n                        domain = [(rec_name, operator, name)]\n                        res = _extend_name_results(\n                            self, base_domain + domain, res, limit)\n                    # Try ordered word search on each of the search fields\n                    for rec_name in all_names:\n                        domain = [(rec_name, operator, name.replace(' ', '%'))]\n                        res = _extend_name_results(\n                            self, base_domain + domain, res, limit)\n                    # Try unordered word search on each of the search fields\n                    for rec_name in all_names:\n                        domain = [(rec_name, operator, x)\n                                  for x in name.split() if x]\n                        res = _extend_name_results(\n                            self, base_domain + domain, res, limit)\n                return res\n            return name_search\n\n        if ids is None:\n            ids = self.search(cr, SUPERUSER_ID, [])\n        for model in self.browse(cr, SUPERUSER_ID, ids):\n            Model = self.pool.get(model.model)\n            if Model:\n                Model._patch_method('name_search', make_name_search())\n        return super(ModelExtended, self)._register_hook(cr)\n", "path": "base_name_search_improved/models/ir_model.py"}]}