Jelajahi Sumber

HUE-3954 [search] Editing record more than once will error because of old version id

Romain Rigaux 9 tahun lalu
induk
melakukan
e33db63c8c

+ 9 - 1
apps/search/src/search/static/search/js/search.ko.js

@@ -1692,14 +1692,22 @@ var SearchViewModel = function (collection_json, query_json, initial_json) {
       document: ko.mapping.toJSON(doc),
       id: doc.id
     }, function (data) {
+      data = JSON.bigdataParse(data);
       if (data.status == 0) {
         doc.showEdit(false);
+
+        var versionField = $.grep(doc.details(), function(field) { return field.key() == '_version_'; });
+        if (versionField.length > 0) {
+          versionField[0].value( data.update.adds[1]);
+          versionField[0].hasChanged(false);
+        };
+
         doc.originalDetails(ko.toJSON(doc.details()));
       }
       else {
         $(document).trigger("error", data.message);
       }
-    }).fail(function (xhr, textStatus, errorThrown) {
+    }, "text").fail(function (xhr, textStatus, errorThrown) {
       $(document).trigger("error", xhr.responseText);
     });
   };

+ 5 - 5
apps/search/src/search/views.py

@@ -356,14 +356,14 @@ def update_document(request):
       version = None # If there is a version, use it to avoid potential concurrent update conflicts
 
       for field in document['details']:
-        if field['hasChanged']:
+        if field['hasChanged'] and field['key'] != '_version_':
           edits[field['key']] = {"set": field['value']}
         if field['key'] == '_version_':
           version = field['value']
 
-      if SolrApi(SOLR_URL.get(), request.user).update(collection['name'], json.dumps([edits]), content_type='json', version=version):
-        result['status'] = 0
-        result['message'] = _('Document successfully updated.')
+      result['update'] = SolrApi(SOLR_URL.get(), request.user).update(collection['name'], json.dumps([edits]), content_type='json', version=version)
+      result['message'] = _('Document successfully updated.')
+      result['status'] = 0
     else:
       result['status'] = 0
       result['message'] = _('Document has no modifications to change.')
@@ -371,7 +371,7 @@ def update_document(request):
     try:
       result['message'] = json.loads(e.message)['error']['msg']
     except:
-      LOG.exception('failed to parse json response')
+      LOG.exception('Failed to parse json response')
       result['message'] = force_unicode(e)
   except Exception, e:
     result['message'] = force_unicode(e)

+ 3 - 4
desktop/libs/libsolr/src/libsolr/api.py

@@ -784,8 +784,7 @@ class SolrApi(object):
     elif content_type == 'json':
       content_type = 'application/json'
     else:
-      LOG.error("Could not update index for %s. Unsupported content type %s. Allowed content types: csv" % (collection_or_core_name, content_type))
-      return False
+      LOG.error("Trying to update collection  %s with content type %s. Allowed content types: csv/json" % (collection_or_core_name, content_type))
 
     params = self._get_params() + (
         ('wt', 'json'),
@@ -796,5 +795,5 @@ class SolrApi(object):
         ('_version_', version),
         ('versions', 'true')
       )
-    self._root.post('%s/update' % collection_or_core_name, contenttype=content_type, params=params, data=data)
-    return True
+    response = self._root.post('%s/update' % collection_or_core_name, contenttype=content_type, params=params, data=data)
+    return self._get_json(response)