Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Add test and fix for invalid key path exceptions with dynamic mapping…

…s. refs #1111
  • Loading branch information...
commit 312b382f258e54c2c3ffb3924665c24a98769039 1 parent b23ea41
@blakewatters blakewatters authored
View
12 Code/Network/RKManagedObjectRequestOperation.m
@@ -533,7 +533,17 @@ - (BOOL)deleteLocalObjectsMissingFromMappingResult:(RKMappingResult *)result wit
for (RKMappingGraphVisitation *visitation in visitor.visitations) {
id objectsAtRoot = [mappingResultDictionary objectForKey:visitation.rootKey];
- id managedObjects = visitation.keyPath ? [objectsAtRoot valueForKeyPath:visitation.keyPath] : objectsAtRoot;
+ id managedObjects = nil;
+ @try {
+ managedObjects = visitation.keyPath ? [objectsAtRoot valueForKeyPath:visitation.keyPath] : objectsAtRoot;
+ }
+ @catch (NSException *exception) {
+ if ([exception.name isEqualToString:NSUndefinedKeyException]) {
+ RKLogWarning(@"Caught undefined key exception for keyPath '%@' in mapping result: This likely indicates an ambiguous keyPath is used across response descriptor or dynamic mappings.", visitation.keyPath);
+ continue;
+ }
+ [exception raise];
+ }
[managedObjectsInMappingResult unionSet:RKFlattenCollectionToSet(managedObjects)];
if (visitation.isCyclic) {
View
8 Tests/Logic/Network/RKManagedObjectRequestOperationTest.m
@@ -671,12 +671,12 @@ - (void)testMappingWithDynamicMappingContainingIncompatibleEntityMappingsAtSameK
[parentMapping addAttributeMappingsFromDictionary:@{ @"name": @"name", @"humanID": @"railsID" }];
[parentMapping addPropertyMapping:[RKRelationshipMapping relationshipMappingFromKeyPath:@"children" toKeyPath:@"children" withMapping:childMapping]];
- [dynamicMapping addMatcher:[RKObjectMappingMatcher matcherWithKeyPath:@"invalid" expectedValue:@"whatever" objectMapping:humanMapping]];
- [dynamicMapping addMatcher:[RKObjectMappingMatcher matcherWithKeyPath:@"name" expectedValue:@"Blake" objectMapping:parentMapping]];
+ [dynamicMapping addMatcher:[RKObjectMappingMatcher matcherWithKeyPath:@"invalid" expectedValue:@"whatever" objectMapping:parentMapping]];
+ [dynamicMapping addMatcher:[RKObjectMappingMatcher matcherWithKeyPath:@"name" expectedValue:@"Blake" objectMapping:humanMapping]];
- RKResponseDescriptor *responseDescriptor = [RKResponseDescriptor responseDescriptorWithMapping:dynamicMapping pathPattern:nil keyPath:@"houses.owner" statusCodes:[NSIndexSet indexSetWithIndex:200]];
+ RKResponseDescriptor *responseDescriptor = [RKResponseDescriptor responseDescriptorWithMapping:dynamicMapping pathPattern:nil keyPath:nil statusCodes:[NSIndexSet indexSetWithIndex:200]];
- NSURLRequest *request = [NSURLRequest requestWithURL:[NSURL URLWithString:@"/JSON/humans/nested_self_referential.json" relativeToURL:[RKTestFactory baseURL]]];
+ NSURLRequest *request = [NSURLRequest requestWithURL:[NSURL URLWithString:@"/JSON/humans/self_referential.json" relativeToURL:[RKTestFactory baseURL]]];
RKManagedObjectRequestOperation *managedObjectRequestOperation = [[RKManagedObjectRequestOperation alloc] initWithRequest:request responseDescriptors:@[ responseDescriptor ]];
RKFetchRequestBlock humanFetchRequestBlock = ^NSFetchRequest * (NSURL *URL) {
return [NSFetchRequest fetchRequestWithEntityName:@"Human"];
Please sign in to comment.
Something went wrong with that request. Please try again.