Skip to content

Commit

Permalink
[Backport to 3.3.x][Fixes #9186] Upload marks as PROCESSED a resource…
Browse files Browse the repository at this point in the history
… not ready yet (#9191)
  • Loading branch information
Alessio Fabiani authored Apr 20, 2022
1 parent 1633775 commit b8c81ed
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 21 deletions.
2 changes: 1 addition & 1 deletion geonode/base/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -1384,7 +1384,7 @@ def clear_dirty_state(self):
def set_processing_state(self, state):
if state == "PROCESSED":
self.clear_dirty_state()
else:
elif state == "INVALID":
self.set_dirty_state()

@property
Expand Down
6 changes: 4 additions & 2 deletions geonode/upload/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -209,7 +209,9 @@ def progress(self):
elif self.state == Upload.STATE_WAITING:
return 50.0
elif self.state == Upload.STATE_PROCESSED:
return 100.0
if self.layer and self.layer.processed:
return 100.0
return 80.0
elif self.state in (Upload.STATE_COMPLETE, Upload.STATE_RUNNING):
if self.layer and self.layer.processed and self.layer.instance_is_processed:
self.state = Upload.STATE_PROCESSED
Expand Down Expand Up @@ -249,7 +251,7 @@ def get_import_url(self):
return None

def get_detail_url(self):
if self.layer and self.state == Upload.STATE_PROCESSED:
if self.layer and self.layer.processed:
return getattr(self.layer, 'detail_url', None)
else:
return None
Expand Down
17 changes: 3 additions & 14 deletions geonode/upload/tasks.py
Original file line number Diff line number Diff line change
Expand Up @@ -206,20 +206,9 @@ def _update_upload_session_state(self, upload_session_id: int):
_response = final_step_view(None, _upload.get_session)
if _response:
_upload.refresh_from_db()
_content = _response.content
if isinstance(_content, bytes):
_content = _content.decode('UTF-8')
_response_json = json.loads(_content)
_success = _response_json.get('success', False)
if _upload.state != Upload.STATE_PROCESSED:
if _upload.layer and _upload.layer.processed:
# GeoNode Layer successfully processed...
_upload.set_processing_state(Upload.STATE_PROCESSED)
else:
# GeoNode Layer updating...
_upload.set_processing_state(Upload.STATE_RUNNING)
elif _upload.layer and _upload.layer.processed:
_upload.set_processing_state(Upload.STATE_PROCESSED)
if _upload.state not in (Upload.STATE_PROCESSED, Upload.STATE_RUNNING) and not _upload.layer:
# GeoNode Layer still updating...
_upload.set_processing_state(Upload.STATE_RUNNING)
logger.debug(f"Upload {upload_session_id} updated with state {_upload.state}.")
except (NotFound, Exception) as e:
logger.exception(e)
Expand Down
12 changes: 8 additions & 4 deletions geonode/upload/upload.py
Original file line number Diff line number Diff line change
Expand Up @@ -705,7 +705,7 @@ def final_step(upload_session, user, charset="UTF-8", layer_id=None):
_vals['store'] = task.target.name
_vals['workspace'] = task.target.workspace_name

elif import_session.state == Upload.STATE_INCOMPLETE and task.state != 'ERROR':
elif import_session.state == Upload.STATE_INCOMPLETE and _tasks_failed:
Upload.objects.invalidate_from_session(upload_session)
raise Exception(f'unknown item state: {task.state}')
try:
Expand Down Expand Up @@ -888,15 +888,17 @@ def final_step(upload_session, user, charset="UTF-8", layer_id=None):

assert saved_layer

# Hide the dataset until the upload process finishes...
saved_layer.set_processing_state(Upload.STATE_RUNNING)
saved_layer.set_dirty_state()
_log(f" -- Finalizing Upload for {saved_layer}... {Upload.STATE_RUNNING}")

# Update the state from session...
upload_session = Upload.objects.update_from_session(upload_session, layer=saved_layer)

if not created and not overwrite:
return saved_layer

# Hide the layer until the upload process finishes...
saved_layer.set_dirty_state()

# Finalize the upload...
# Set default permissions on the newly created layer and send notifications
permissions = upload_session.permissions
Expand Down Expand Up @@ -1030,6 +1032,8 @@ def _store_file(saved_layer,
logger.exception(e)
Upload.objects.filter(layer=saved_layer).update(complete=False)
[u.set_processing_state(Upload.STATE_INVALID) for u in Upload.objects.filter(layer=saved_layer)]
finally:
_log(f" -- Upload completed for {saved_layer}...")

return saved_layer

Expand Down

0 comments on commit b8c81ed

Please sign in to comment.