From 3f50008d45f8416f25901fa2450b3fd19514eaff Mon Sep 17 00:00:00 2001
From: Benjamin Bertrand <benjamin.bertrand@esss.se>
Date: Mon, 15 Oct 2018 08:36:53 +0200
Subject: [PATCH] Fix TypeError in after_commit

session._changes can be None in after_commit
See https://sentry.esss.lu.se/sentry/csentry/issues/63

JIRA INFRA-613 #action In Progress
---
 app/models.py | 4 ++++
 1 file changed, 4 insertions(+)

diff --git a/app/models.py b/app/models.py
index 8186bf5..5ba6e8f 100644
--- a/app/models.py
+++ b/app/models.py
@@ -373,6 +373,8 @@ class SearchableMixin(object):
     @classmethod
     def after_flush_postexec(cls, session, flush_context):
         """Retrieve the new and updated objects representation"""
+        if session._changes is None:
+            return
         # - We can't call obj.to_dict() in the before_flush event because the id
         #   hasn't been allocated yet (for new objects) and other fields haven't been updated
         #   (default values like created_at/updated_at and some relationships).
@@ -387,6 +389,8 @@ class SearchableMixin(object):
     @classmethod
     def after_commit(cls, session):
         """Update the elasticsearch index"""
+        if session._changes is None:
+            return
         for index, body in session._changes["add"]:
             search.add_to_index(index, body)
         for index, id in session._changes["delete"]:
-- 
GitLab