Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
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
bbafde3
There was a problem hiding this comment.
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](IEnumerable
1 value) at Newtonsoft.Json.Linq.Extensions.Value[U](IEnumerable
1 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();
bbafde3
There was a problem hiding this comment.
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")
bbafde3
There was a problem hiding this comment.
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();
}
}