Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
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
Martin Murphy authored and henrikwallstrom committed Jun 2, 2010
1 parent 510a86d commit bbafde3
Showing 1 changed file with 2 additions and 1 deletion.
3 changes: 2 additions & 1 deletion src/CouchQueryDocument.cs
Expand Up @@ -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

@brewmanz
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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();

@brewmanz
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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")

@brewmanz
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.