Skip to content

Commit

Permalink
Fixing issues with how multi load can now return nulls
Browse files Browse the repository at this point in the history
  • Loading branch information
ayende committed Jan 30, 2012
1 parent 85bf5d7 commit 47a7293
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 10 deletions.
27 changes: 18 additions & 9 deletions Raven.Client.Lightweight/Connection/SerializationHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -27,22 +27,31 @@ public static class SerializationHelper
///</summary>
public static IEnumerable<JsonDocument> RavenJObjectsToJsonDocuments(IEnumerable<RavenJObject> responses)
{
return (from doc in responses
let metadata = doc["@metadata"] as RavenJObject
let _ = doc.Remove("@metadata")
let key = Extract(metadata, "@id", string.Empty)
let lastModified = Extract(metadata, Constants.LastModified, SystemTime.Now, (string d) => ConvertToUtcDate(d))
let etag = Extract(metadata, "@etag", Guid.Empty, (string g) => new Guid(g))
let nai = Extract(metadata, "Non-Authoritative-Information", false, (string b) => Convert.ToBoolean(b))
select new JsonDocument
var list = new List<JsonDocument>();
foreach (var doc in responses)
{
if(doc == null)

This comment has been minimized.

Copy link
@cubanx

cubanx Feb 8, 2012

@ayende Now that null can be in the return collection, this line:

results.Any(x => x.NonAuthoritiveInformation ?? false) &&

..can throw a NRE. We have this happening in our current codebase.

I can provide a test case that shows this if need be.

This comment has been minimized.

Copy link
@ayende

ayende via email Feb 8, 2012

Author Member

This comment has been minimized.

Copy link
@cubanx

cubanx Feb 8, 2012

Excellent, thanks for the quick turn around.

This comment has been minimized.

Copy link
@cubanx

cubanx Feb 8, 2012

Any idea on when/what build this will be in?

This comment has been minimized.

Copy link
@ravendb

ravendb via email Feb 8, 2012

Collaborator
{
list.Add(null);
continue;
}
var metadata = (RavenJObject)doc["@metadata"];
doc.Remove("@metadata");
var key = Extract(metadata, "@id", string.Empty);
var lastModified = Extract(metadata, Constants.LastModified, SystemTime.Now, (string d) => ConvertToUtcDate(d));
var etag = Extract(metadata, "@etag", Guid.Empty, (string g) => new Guid(g));
var nai = Extract(metadata, "Non-Authoritative-Information", false, (string b) => Convert.ToBoolean(b));
list.Add(new JsonDocument
{
Key = key,
LastModified = lastModified,
Etag = etag,
NonAuthoritativeInformation = nai,
Metadata = metadata.FilterHeaders(isServerDocument: false),
DataAsJson = doc,
}).ToList();
});
}
return list;
}

///<summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ public T[] Complete<T>()
}

return results
.Select(sessionOperations.TrackEntity<T>)
.Select(document => document == null ? default(T) : sessionOperations.TrackEntity<T>(document))
.ToArray();
}
}
Expand Down

0 comments on commit 47a7293

Please sign in to comment.