Skip to content
Snippets Groups Projects
Commit 3f50008d authored by Benjamin Bertrand's avatar Benjamin Bertrand
Browse files

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
parent 6042d531
No related branches found
No related tags found
No related merge requests found
...@@ -373,6 +373,8 @@ class SearchableMixin(object): ...@@ -373,6 +373,8 @@ class SearchableMixin(object):
@classmethod @classmethod
def after_flush_postexec(cls, session, flush_context): def after_flush_postexec(cls, session, flush_context):
"""Retrieve the new and updated objects representation""" """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 # - 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 # 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). # (default values like created_at/updated_at and some relationships).
...@@ -387,6 +389,8 @@ class SearchableMixin(object): ...@@ -387,6 +389,8 @@ class SearchableMixin(object):
@classmethod @classmethod
def after_commit(cls, session): def after_commit(cls, session):
"""Update the elasticsearch index""" """Update the elasticsearch index"""
if session._changes is None:
return
for index, body in session._changes["add"]: for index, body in session._changes["add"]:
search.add_to_index(index, body) search.add_to_index(index, body)
for index, id in session._changes["delete"]: for index, id in session._changes["delete"]:
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment