diff --git a/js/data/RestDataSource.js b/js/data/RestDataSource.js
index <HASH>..<HASH> 100644
--- a/js/data/RestDataSource.js
+++ b/js/data/RestDataSource.js
@@ -20,7 +20,7 @@ define(["js/data/DataSource", "js/data/Model", "underscore", "flow", "JSON", "js
                     configuration = configuration.$parent;
                 }
                 var i = 0;
-                while(scopeStack[i].$.path === subModelStack[i].$.path){
+                while(scopeStack[i] && subModelStack[i] && scopeStack[i].$.path === subModelStack[i].$.path){
                     i++;
                 }
                 contextDistance = subModelStack.length - i;
added null check in RestDataSource