Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Regression in .compact? #3350

Closed
tlvince opened this issue Jan 6, 2015 · 9 comments
Closed

Regression in .compact? #3350

tlvince opened this issue Jan 6, 2015 · 9 comments

Comments

@tlvince
Copy link
Contributor

tlvince commented Jan 6, 2015

In 3.2.1, given:

var db = new PouchDB('db');
db.compact()
  .then(function(response) {
    console.log(response);
  })
  .catch(function(error) {
    console.error(error);
  });

… logs undefined. Same if I use callbacks. In 3.2.0, this is returning the _local/compaction response as expected.

NB, also note I'm seeing a possible migration error if I run the 3.2.0 test case after 3.2.1:

// Promise
[Error] TypeError: undefined is not a function (evaluating 'tasks[i - 1](tx, nextMigration)')
    (anonymous function) (pouchdb.js, line 3949)

// Callback
[Error] {"status":500,"name":"Object","message":"the statement callback raised an exception or statement error callback did not return false"}
    (anonymous function) (d97da61674b027c83f161854bbbd97139efcb9a8, line 24)
tlvince added a commit to angular-pouchdb/angular-pouchdb that referenced this issue Jan 6, 2015
In PouchDB 3.2.1, `compact` is returning `undefined` (on success) rather than a
compaction response. See pouchdb/pouchdb#3350
@nolanlawson
Copy link
Member

Yep, I forgot to mention in the blog post that there is a migration. I'll fix that.

As for compact, it's supposed to resolve with {ok: true} because that's what CouchDB does. Neither the 3.2.0 behavior nor the 3.2.1 behavior is correct. A pull request would be welcome. :)

@marten-de-vries
Copy link
Member

So compact() has always resolved to undefined until 3.2.0. For 3.2.1 it was changed back (#3111).

Changing it to the CouchDB-like {ok: true} makes sense, but is technically a backward-incompatible api change (so 4.0)?

@tlvince
Copy link
Contributor Author

tlvince commented Jan 6, 2015

Thanks for the heads up.

3.2.0 is resolving something like:

{
  id: '_local/compaction',
  ok: true,
  rev: '0-2'
}

… which makes more sense to me than a straight undefined, but agreed, mirroring what CouchDB does is best.

@nolanlawson
Copy link
Member

@tlvince _local/compaction is an implementation detail; I think it was a bug that we ever exposed it.

@marten-de-vries AFAIK the docs have always been silent about what the promise is supposed to resolve with. So I don't see it as a breaking change; just a bug.

BTW I confirmed that {ok:true} is what CouchDB does:

$ curl -X POST http://127.0.0.1:5984/test/_compact -H 'Content-type:application/json' -d '{}'
{"ok":true}

tlvince added a commit to angular-pouchdb/angular-pouchdb that referenced this issue Jan 6, 2015
.compact returning `undefined` on success is the expected behaviour in PouchDB
v3.2.1.

Refs: pouchdb/pouchdb#3350 (comment)
@marten-de-vries
Copy link
Member

@nolanlawson Alright, I see semver as a bit more strict (don't change return values of methods, period.) But on the other hand I can't see this breaking much except my Python-PouchDB tests, so I'm fine with {ok: true} instead. I'll open a PR for this, since I already changed this once for #3111 I know where to look. 😀

@nolanlawson
Copy link
Member

Thanks, I would just prefer not to introduce a big version change for something that most people will not care about. 😛

Also my rule of thumb is that undocumented behavior is not something we need to adhere strictly to. :)

@marten-de-vries
Copy link
Member

This has been fixed (2786090 & beaddad)

rhiokim added a commit to rhiokim/pouchdb that referenced this issue Jan 9, 2015
* feature/3.2.1: (125 commits)
  (pouchdb#3095) - Use selenium-standalone to manage selenium
  (pouchdb#3364) - Update license, happy new year
  (pouchdb/express-pouchdb#164) - adds SERVER=express-pouchdb-minimum
  (pouchdb#3361) - remove PouchDB.extend
  (pouchdb#2632) - remove browserified Buffer from build
  (pouchdb#2632) - use bundle collapser to reduce min size
  (pouchdb#3155) - Replace syncStopped / started with active / paused
  (pouchdb#3350) - http compact() also returns {ok:true}
  (pouchdb#3350) - make compact return {ok: true}
  (pouchdb#136) - Skip "issue pouchdb#2393 update_seq after new_edits + replication"
  (pouchdb#3350) - add warning about 3.2.1 migration
  (pouchdb#3279) - update to 3.2.2-prerelease
  (pouchdb#3279) - 3.2.1 blog post
  (pouchdb#2632) - remove leveldb from browserify build
  (pouchdb#3345) - correctly report auto_compaction in info()
  (pouchdb#136) - Return correct checkpoint for CouchDB 2.x
  (pouchdb#136) - Fix "Replication since" / CouchDB 2.0
  (pouchdb/mapreduce#239) - fix dep dbs with db/prefix option
  (pouchdb#136) - Fix "Reporting write failures (pouchdb#942)"
  (pouchdb#3326) - fix blob support in chrome
  ...
tlvince added a commit to angular-pouchdb/angular-pouchdb that referenced this issue Jan 16, 2015
In PouchDB 3.2.1, `compact` is returning `undefined` (on success) rather than a
compaction response. See pouchdb/pouchdb#3350
tlvince added a commit to angular-pouchdb/angular-pouchdb that referenced this issue Jan 16, 2015
.compact returning `undefined` on success is the expected behaviour in PouchDB
v3.2.1.

Refs: pouchdb/pouchdb#3350 (comment)
@davidpfahler
Copy link

Hi all, I'm not sure how to exactly articulate this, but this breaks existing code of mine completely. Some of you said that this would not be an actual regression but only in tests, so I wanted to let you know this isn't the case.

I have my pouch db set to ^3.1.0 in my package.json. I don't know what exact version it had when I last touched it and it still worked, but I can definitely tell you that when I upgraded to 3.2.1, this broke my entire database on second load (i.e. after it was compacted once). I had my PouchDB set to auto_compaction: true. When I disabled this setting, deleted all data and started the app again, the error went away. My exact error message was: "undefined is not a function (evaluating 'tasks[i - 1](tx, nextmigration)')" which is how I found this issue.

@nolanlawson
Copy link
Member

@davidpfahler that nextmigration thing is migration code... was this in WebSQL or IndexedDB?

If you can provide a test case to reproduce, that would be great, although I understand that this kind of migration stuff is tricky. 😛

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants