Permalink
Browse files

BugFix

    When null was emitted for the value it was failing.
New behavior assigns null to Rev when _rev cannot be found in the value emitted.
  • Loading branch information...
1 parent 510a86d commit bbafde3a4e24deea1d2ef17aa13324e3927c5e22 @soitgoes soitgoes committed with henrikwallstrom May 10, 2010
Showing with 2 additions and 1 deletion.
  1. +2 −1 src/CouchQueryDocument.cs
@@ -13,7 +13,8 @@ public override void ReadJson(JObject obj)
{
Id = obj["id"].Value<string>();
Key = obj["key"].Value<string>();
- Rev = (obj["value"].Value<JObject>())["rev"].Value<string>();
+ var tmp = obj["value"];
+ Rev = tmp.ToString() == "null" ? null : tmp.Value<JObject>()["_rev"].Value<string>(); //Rev is null if the value emitted is not doc or does not contain _rev
}
}
}

3 comments on commit bbafde3

This code fails in Unit test

at Newtonsoft.Json.Utilities.ValidationUtils.ArgumentNotNull(Object value, String parameterName)
at Newtonsoft.Json.Linq.Extensions.Value[T,U](IEnumerable1 value) at Newtonsoft.Json.Linq.Extensions.Value[U](IEnumerable1 value)
at Divan.CouchQueryDocument.ReadJson(JObject obj) in C:\SVN\Divan\src\CouchQueryDocument.cs:line 17
at Divan.CouchGenericViewResult.RowDocumentsT in C:\SVN\Divan\src\CouchGenericViewResult.cs:line 193
at Divan.CouchGenericViewResult.RowDocuments() in C:\SVN\Divan\src\CouchGenericViewResult.cs:line 184
at Divan.CouchDatabase.DeleteDocuments(String startKey, String endKey) in C:\SVN\Divan\src\CouchDatabase.cs:line 718

at Divan.Test.CouchTest.ShouldDeleteDocuments() in C:\SVN\Divan\Tests\CouchTest.cs:line 135

(I have about 1 hour experience of using CouchDB and no experience of its internals; sorry if I've completely misunderstood something here)
There seems to be confusion about whether the key(?) is "_rev" or "rev". (similarly elsewhere there is "_id" and "id")
I suggest using constants rather than string literals; e.g.
Rev = tmp.ToString() == CouchDocument.kNull ? null : tmp.Value()[CouchDocument.kRevKey].Value();

my embedded hyphens and underscores seem to have been taken as formatting symbols! My comments should read ...
confusion about whether the key(?) is "rev" or "underscore rev". (similarly elsewhere there is "id" and "underscore id")

The following code is ugly, but allows the Unit Tests to work (NB replace 'underscore' with .. something)
public override void ReadJson(JObject obj)
{
Id = obj["id"].Value();
Key = obj["key"].Value();
var tmp = obj["value"];
//Rev = tmp.ToString() == "null" ? null : tmp.Value()["underscore rev"].Value(); //Rev is null if the value emitted is not doc or does not contain _rev
if (tmp.ToString() == "null")
Rev = null;
else
{
var preUnderscoreRev = tmp.Value()["underscore rev"];
var preRev = tmp.Value()["rev"];
Rev = (preRev ?? preUnderscoreRev).Value();
}
}

Please sign in to comment.