"""
Just some useful Flask stuff for ndb.
"""
from google.appengine.ext import ndb
from flask import g

from app import app


def put_later(*objs):
    """
    Any ndb model instances passed to this method will be put after the flask request has been processed.
    """
    for obj in objs:
        if obj not in g.dirty_ndb:
            g.dirty_ndb.append(obj)

@app.after_request
def store_ndb(response):
    """
    Puts the contents of g.dirty_ndb
    """
    if g.dirty_ndb:
        ndb.put_multi(g.dirty_ndb)
        g.dirty_ndb = []
    return response


"""
Just some useful Flask stuff for ndb.
"""
from google.appengine.ext import ndb
from flask import g

from app import app


def put_later(*objs):
    """
    Any ndb model instances passed to this method will be put after the flask request has been processed.
    """
    for obj in objs:
        if obj not in g.dirty_ndb:
            g.dirty_ndb.append(obj)

@app.after_request
def store_ndb(response):
    """
    Puts the contents of g.dirty_ndb
    """
    try:
        if g.dirty_ndb:
            ndb.put_multi(g.dirty_ndb)
            g.dirty_ndb = []
    finally:
        return response


--- 
+++ 
@@ -20,10 +20,8 @@
     """
     Puts the contents of g.dirty_ndb
     """
-    try:
-        if g.dirty_ndb:
-            ndb.put_multi(g.dirty_ndb)
-            g.dirty_ndb = []
-    finally:
-        return response
+    if g.dirty_ndb:
+        ndb.put_multi(g.dirty_ndb)
+        g.dirty_ndb = []
+    return response
 
Fix bug where dirty_ndb was silently failing.
