Skip to content

Commit

Permalink
Log a diff of the ES document and serialized enrollment (#3657)
Browse files Browse the repository at this point in the history
* Log a diff of the ES document and serialized enrollment

* Revert upgrade of psycopg2
  • Loading branch information
George Schneeloch authored Oct 31, 2017
1 parent 8d874e3 commit 171a800
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 1 deletion.
2 changes: 2 additions & 0 deletions requirements.in
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ Django==1.10.5
Pillow==3.4.2
boto==2.39.0
celery==4.0.2
deepdiff==3.3.0
dj-database-url==0.3.0
dj-static==0.0.6
django-cors-headers==2.1.0
Expand All @@ -21,6 +22,7 @@ gnupg==2.2.0
html5lib==0.999999999
ipython
jsonfield==1.0.3
jsonpatch==1.16
newrelic
open-discussions-client==0.2.2
phonenumbers==8.3.2
Expand Down
3 changes: 3 additions & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ cffi==1.10.0 # via bcrypt, cryptography, pynacl
contextlib2==0.5.5 # via raven
cryptography==2.0.2 # via paramiko
decorator==4.1.2 # via ipython, traitlets
deepdiff==3.3.0
defusedxml==0.5.0 # via python3-openid, social-auth-core
dj-database-url==0.3.0
dj-static==0.0.6
Expand Down Expand Up @@ -43,6 +44,8 @@ ipython-genutils==0.2.0 # via traitlets
ipython==6.1.0
jedi==0.10.2 # via ipython
jsonfield==1.0.3
jsonpatch==1.16
jsonpointer==1.12 # via jsonpatch
kombu==4.1.0 # via celery, django-server-status
newrelic==2.88.1.73
oauthlib==2.0.2 # via requests-oauthlib, social-auth-core
Expand Down
19 changes: 18 additions & 1 deletion search/api.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,15 @@
"""
Functions for executing ES searches
"""
import json
import logging

from django.conf import settings
from django.core.exceptions import ImproperlyConfigured
from django.db.models import Q as Query
from elasticsearch.exceptions import NotFoundError
from elasticsearch_dsl import Search, Q
from jsonpatch import make_patch

from courses.models import Program
from dashboard.models import ProgramEnrollment
Expand All @@ -27,6 +31,9 @@
DEFAULT_ES_LOOP_PAGE_SIZE = 100


log = logging.getLogger(__name__)


def execute_search(search_obj):
"""
Executes a search against ES after checking the connection
Expand Down Expand Up @@ -300,4 +307,14 @@ def document_needs_updating(enrollment):
return True
serialized_enrollment = serialize_program_enrolled_user(enrollment)
del serialized_enrollment['_id']
return serialized_enrollment != document['_source']
source = document['_source']

if serialized_enrollment != source:
# Convert OrderedDict to dict
reserialized_enrollment = json.loads(json.dumps(serialized_enrollment))

diff = make_patch(source, reserialized_enrollment).patch
serialized_diff = json.dumps(diff, indent=" ")
log.info("Difference found for enrollment %s: %s", enrollment, serialized_diff)
return True
return False

0 comments on commit 171a800

Please sign in to comment.