Merge lp:~chipaca/u1db/whoops_i_did_it_again into lp:u1db

Proposed by John Lenton
Status: Merged
Approved by: dobey
Approved revision: 304
Merge reported by: dobey
Merged at revision: not available
Proposed branch: lp:~chipaca/u1db/whoops_i_did_it_again
Merge into: lp:u1db
Diff against target: 60 lines (+26/-2)
3 files modified
src/u1db_query.c (+20/-1)
u1db/backends/sqlite_backend.py (+2/-1)
u1db/tests/test_backends.py (+4/-0)
To merge this branch: bzr merge lp:~chipaca/u1db/whoops_i_did_it_again
Reviewer Review Type Date Requested Status
John A Meinel (community) Approve
Samuele Pedroni Approve
Eric Casteleijn (community) Approve
Review via email: mp+106665@code.launchpad.net

Commit message

Fix #1002375 (stop get_keys_from_index throwing IndexDoesNotExist on existing but empty indexes)

Description of the change

I introduced a bug in r302 where get_keys_from_index fails with IndexDoesNotExist in the case where the index exists but has no matches. This fixes that.

To post a comment you must log in.
Revision history for this message
Eric Casteleijn (thisfred) wrote :

Again looks good, and I looked harder and longer.

review: Approve
Revision history for this message
Samuele Pedroni (pedronis) wrote :

+1

review: Approve
Revision history for this message
John A Meinel (jameinel) wrote :

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

On 5/21/2012 6:36 PM, John Lenton wrote:
> John Lenton has proposed merging
> lp:~chipaca/u1db/whoops_i_did_it_again into lp:u1db.
>
> Requested reviews: Ubuntu One hackers (ubuntuone-hackers) Related
> bugs: Bug #1002375 in U1DB: "get_index_keys fails with
> IndexDoesNotExist when index exists but has nothing indexed."
> https://bugs.launchpad.net/u1db/+bug/1002375
>
> For more details, see:
> https://code.launchpad.net/~chipaca/u1db/whoops_i_did_it_again/+merge/106665
>
> I introduced a bug in r302 where get_keys_from_index fails with
> IndexDoesNotExist in the case where the index exists but has no
> matches. This fixes that.

 merge: approve

John
=:->

-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.9 (Cygwin)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org/

iEYEARECAAYFAk+7XCEACgkQJdeBCYSNAAMBBQCgu+XTE0Ff+mcEvQf83EYK/Zmq
R4wAn21sEZyaheGP9bpr22utQwXYoO1X
=aT3m
-----END PGP SIGNATURE-----

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'src/u1db_query.c'
2--- src/u1db_query.c 2012-05-21 15:01:18 +0000
3+++ src/u1db_query.c 2012-05-21 16:37:19 +0000
4@@ -631,7 +631,26 @@
5 }
6 status = sqlite3_step(statement);
7 if (status == SQLITE_DONE) {
8- status = U1DB_INDEX_DOES_NOT_EXIST;
9+ sqlite3_finalize(statement);
10+ status = sqlite3_prepare_v2(
11+ db->sql_handle,
12+ "SELECT field FROM index_definitions WHERE name = ?;",
13+ -1, &statement, NULL);
14+ if (status != SQLITE_OK) {
15+ goto finish;
16+ }
17+ status = sqlite3_bind_text(
18+ statement, 1, index_name, -1, SQLITE_TRANSIENT);
19+ if (status != SQLITE_OK) {
20+ goto finish;
21+ }
22+ status = sqlite3_step(statement);
23+ if (status == SQLITE_DONE) {
24+ status = U1DB_INDEX_DOES_NOT_EXIST;
25+ } else {
26+ status = U1DB_OK;
27+ }
28+ goto finish;
29 }
30 while (status == SQLITE_ROW) {
31 key = (char*)sqlite3_column_text(statement, 0);
32
33=== modified file 'u1db/backends/sqlite_backend.py'
34--- u1db/backends/sqlite_backend.py 2012-05-21 15:01:18 +0000
35+++ u1db/backends/sqlite_backend.py 2012-05-21 16:37:19 +0000
36@@ -622,7 +622,8 @@
37 '\nstatement: %s\nargs: %s\n' % (SQL_INDEX_KEYS, (index,)))
38 res = c.fetchall()
39 if not res:
40- raise errors.IndexDoesNotExist
41+ # raise IndexDoesNotExist if appropriate
42+ self._get_index_definition(index)
43 return [r[0] for r in res]
44
45 def delete_index(self, index_name):
46
47=== modified file 'u1db/tests/test_backends.py'
48--- u1db/tests/test_backends.py 2012-05-21 15:01:18 +0000
49+++ u1db/tests/test_backends.py 2012-05-21 16:37:19 +0000
50@@ -733,6 +733,10 @@
51 self.db.get_index_keys,
52 'foo')
53
54+ def test_get_index_keys_works_if_no_docs(self):
55+ self.db.create_index('test-idx', ['key'])
56+ self.assertEqual([], self.db.get_index_keys('test-idx'))
57+
58 def test_put_updates_index(self):
59 doc = self.db.create_doc(simple_doc)
60 self.db.create_index('test-idx', ['key'])

Subscribers

People subscribed via source and target branches