impossible to use boolean indexes

Bug #1176363 reported by Viesturs Teivāns
6
This bug affects 1 person
Affects Status Importance Assigned to Milestone
U1DB
Fix Released
Undecided
Samuele Pedroni

Bug Description

Hello, I am using u1db for my Ubuntu app and I wanted to use an index with Boolean value, like in the tutorial (cosas), but it seems not to be passable to get documents by boolean index.

So i define the indexes
LAST_INDEX = 'last'
...
INDEXES = {
 LAST_INDEX: ['bool(last)']
...
}

And create them in for loop just like in tutorial:
for name, expression in INDEXES.items():
 self.db.create_index(name, *expression)

So far so good
but when I try to get something from boolean index, like this:
db.get_from_index(LAST_INDEX, True)

I get an error:
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/usr/lib/python2.7/dist-packages/u1db/backends/sqlite_backend.py", line 670, in get_from_index
    statement, args = self._format_query(definition, key_values)
  File "/usr/lib/python2.7/dist-packages/u1db/backends/sqlite_backend.py", line 641, in _format_query
    if value.endswith('*'):
AttributeError: 'bool' object has no attribute 'endswith'

but if I take all elements from index like in tutorial:
db.get_from_index(LAST_INDEX, '*')
it returns all just fine

Tags: u1-notrack

Related branches

Changed in u1db:
assignee: nobody → Samuele Pedroni (pedronis)
Revision history for this message
Lucio Torre (lucio.torre) wrote :

Thanks for your report. We will be looking into it next week.

summary: - impassable to use boolean indexes
+ impossible to use boolean indexes
Revision history for this message
Samuele Pedroni (pedronis) wrote :

the documentation is not clear on this point (we will improve it) but the current version of get_from_index takes always strings for values

so a bool(.) index needs to be queried with:

get_from_index(LAST_INDEX, "0"|"1") where "0" is false and "1" is for true,

similarly for a number(.) index

Changed in u1db:
status: New → Triaged
Revision history for this message
Viesturs Teivāns (vteivans) wrote :

Thanks for your replay. I only tried "True" and "False" like strings.

Dave Morley (davmor2)
tags: added: u1-notrack
Revision history for this message
Samuele Pedroni (pedronis) wrote :

the new expanded documentation is up at

https://one.ubuntu.com/developer/data/u1db/high-level-api

Changed in u1db:
status: Triaged → Fix Released
To post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Other bug subscribers

Remote bug watches

Bug watches keep track of this bug in other bug trackers.