Bug 5962

Summary: The "Local configuration variables" filter returns an error when applied on top of search results
Product: [Build System, Metadata & Runtime] Toaster Reporter: Belen Barros Pena <belen.barros.pena>
Component: toasterAssignee: David Reyna <david.reyna>
Status: VERIFIED FIXED QA Contact:
Severity: normal    
Priority: Medium CC: alexandru.damian, belen.barros.pena, cristiana.voicu, jessica.zhang
Version: unspecified   
Target Milestone: 1.6 M5   
Hardware: All   
OS: Multiple   
Whiteboard:
OS type for building Yocto: --- Type of Regression: ---
Verified: Documentation change: No (bug/feature does not impact docs)

Description Belen Barros Pena 2014-03-13 13:51:45 UTC
Steps to reproduce:

1. In Toaster, select a build, go the Configuration page and click on the "BitBake variables" tab

2. Search for something that will return results (for example, "kernel")

3. Click on the "Set in file" filter button and select the "Local configuration variables" option. Click "Apply"

You get this error:

Environment:


Request Method: GET
Request URL: http://localhost:8000/gui/build/65/configvars?filter=vhistory__file_name__regex%3Aconf%2F%28local%7Cbblayers%29.conf&count=100&search=kernel&page=1&orderby=variable_name%3A%2B

Django Version: 1.5
Python Version: 2.7.3
Installed Applications:
('django.contrib.staticfiles',
 'django.contrib.humanize',
 'orm',
 'toastermain',
 'toastergui',
 'bldviewer',
 'south')
Installed Middleware:
('django.middleware.common.CommonMiddleware',
 'django.contrib.sessions.middleware.SessionMiddleware',
 'django.middleware.csrf.CsrfViewMiddleware',
 'django.contrib.auth.middleware.AuthenticationMiddleware',
 'django.contrib.messages.middleware.MessageMiddleware')


Traceback:
File "/usr/local/lib/python2.7/dist-packages/django/core/handlers/base.py" in get_response
  115.                         response = callback(request, *callback_args, **callback_kwargs)
File "/home/yocto/poky/bitbake/lib/toaster/toastergui/views.py" in configvars
  787.     queryset = _get_queryset(Variable, queryset, filter_string, search_term, ordering_string)
File "/home/yocto/poky/bitbake/lib/toaster/toastergui/views.py" in _get_queryset
  187.     if ordering_string and queryset:
File "/usr/local/lib/python2.7/dist-packages/django/db/models/query.py" in __nonzero__
  141.         return type(self).__bool__(self)
File "/usr/local/lib/python2.7/dist-packages/django/db/models/query.py" in __bool__
  135.             next(iter(self))
File "/usr/local/lib/python2.7/dist-packages/django/db/models/query.py" in _result_iter
  123.                 self._fill_cache()
File "/usr/local/lib/python2.7/dist-packages/django/db/models/query.py" in _fill_cache
  939.                     self._result_cache.append(next(self._iter))
File "/usr/local/lib/python2.7/dist-packages/django/db/models/query.py" in _safe_iterator
  344.             for item in iterator:
File "/usr/local/lib/python2.7/dist-packages/django/db/models/query.py" in iterator
  301.         for row in compiler.results_iter():
File "/usr/local/lib/python2.7/dist-packages/django/db/models/sql/compiler.py" in results_iter
  775.         for rows in self.execute_sql(MULTI):
File "/usr/local/lib/python2.7/dist-packages/django/db/models/sql/compiler.py" in execute_sql
  840.         cursor.execute(sql, params)
File "/usr/local/lib/python2.7/dist-packages/django/db/backends/util.py" in execute
  41.             return self.cursor.execute(sql, params)
File "/usr/local/lib/python2.7/dist-packages/django/db/backends/sqlite3/base.py" in execute
  366.             six.reraise(utils.DatabaseError, utils.DatabaseError(*tuple(e.args)), sys.exc_info()[2])
File "/usr/local/lib/python2.7/dist-packages/django/db/backends/sqlite3/base.py" in execute
  362.             return Database.Cursor.execute(self, query, params)

Exception Type: DatabaseError at /gui/build/65/configvars
Exception Value: user-defined function raised exception
Comment 1 David Reyna 2014-03-14 04:15:12 UTC
It is the "regex" filter returning an empty set to a search that leads to the error.

The filter in question is the "vhistory__file_name__regex:conf/(local|bblayers).conf"

If I change the filter to ...
  filter=vhistory__file_name__contains:conf/bblayers.con
... it leads to an empty table and no errors.

If I leave the filter but remove the "search=kernel" I get results returned and no error.
Comment 2 David Reyna 2014-03-14 05:13:38 UTC
The bug is deeper than that, somewhere inside the handling of the lambda function from "_get_search_results" in the Django Q object filtering.

The regex filtering in "_get_queryset" returns a successful queryset with some 20 entries.

Then in "_get_search_results", the Q object filter call for the search terms does return, but the resulting queryset object is damaged, in that any method call ("exists", "count", ...) will immediately cause the reported error. I find that if I replace the Q object with a simple filter (no lamba), there is no error.
Comment 3 Alexandru Damian 2014-03-20 12:20:25 UTC
Is this a bug in the Q() in Django itself ?
Comment 4 Alexandru Damian 2014-03-20 12:32:26 UTC
(In reply to comment #3)
> Is this a bug in the Q() in Django itself ?

No, this is an issue with Sqlite3 engine. reference:
http://www.gossamer-threads.com/lists/python/python/543700
Comment 5 David Reyna 2014-04-09 23:15:23 UTC
commit 74e2f8501997143162855b970ffd9fdb33d24bd8
Comment 6 Belen Barros Pena 2014-04-10 18:06:05 UTC
verified in master:db80f796e78746014a0f9497638e5c6fd2953ef0