Skip to content

Commit

Permalink
Handle errors from load_jsonld command re #10798
Browse files Browse the repository at this point in the history
  • Loading branch information
jacobtylerwalls committed May 2, 2024
1 parent 247f92c commit 7c4087c
Showing 1 changed file with 38 additions and 17 deletions.
55 changes: 38 additions & 17 deletions arches/app/etl_modules/jsonld_importer.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import json
import os
import zipfile
from datetime import datetime
from functools import lru_cache
from pathlib import Path

Expand All @@ -11,7 +11,7 @@

from arches.app.etl_modules.base_import_module import BaseImportModule, FileValidationError
from arches.app.etl_modules.decorators import load_data_async
from arches.app.models.models import GraphModel, LoadErrors, LoadStaging
from arches.app.models.models import GraphModel, LoadErrors, LoadEvent, LoadStaging
from arches.app.models.system_settings import settings
from arches.app.utils.betterJSONSerializer import JSONSerializer
from arches.app.utils.file_validator import FileValidator
Expand Down Expand Up @@ -82,12 +82,13 @@ def read(self, request):

def validate_uploaded_file(self, file):
path = Path(file.name)
slug = path.parts[1]
try:
graph_id_from_slug(path.parts[1])
graph_id_from_slug(slug)
except GraphModel.ObjectDoesNotExist:
raise FileValidationError(
code=404,
message=_('The model "{0}" does not exist.').format(path.parts[1])
message=_('The model "{0}" does not exist.').format(slug)
)

def stage_files(self, files, summary, cursor):
Expand All @@ -110,18 +111,38 @@ def stage_files(self, files, summary, cursor):
graph_id_from_slug.cache_clear()

def handle_block(self, graph_slug, block):
# todo(jtw): add try
resources = call_command(
"load_jsonld",
model=graph_slug,
block=block,
force="overwrite",
source=self.temp_dir,
quiet=True,
fast=True,
use_storage=True,
dry_run=True, # don't save the resources
),
try:
resources = call_command(
"load_jsonld",
model=graph_slug,
block=block,
force="overwrite",
source=self.temp_dir,
quiet=True,
fast=True,
use_storage=True,
dry_run=True, # don't save the resources
)
except Exception as e:
LoadErrors(
load_event_id=self.loadid,
type="graph",
source="/".join((graph_slug, block)),
error=_("Load JSON-LD command error"),
message=e.args[0],
).save()
LoadEvent(
loadid=self.loadid,
user_id=self.userid,
successful=False,
status="failed",
load_description="/".join((graph_slug, block)),
etl_module_id=self.moduleid,
error_message=_("Load JSON-LD command error"),
load_end_time=datetime.now(),
).save()
raise

nodegroup_info, node_info = get_graph_tree_from_slug(graph_slug)
self.populate_staging_table(resources, nodegroup_info, node_info)

Expand Down Expand Up @@ -175,7 +196,7 @@ def load_staging_instance_from_tile(self, tile, resource, nodegroup_info, node_i
def save_validation_errors(self, validation_errors, tile, source_value, datatype, nodeid):
for error in validation_errors:
LoadErrors(
load_event=self.loadid,
load_event_id=self.loadid,
nodegroup_id=tile.nodegroup_id,
node_id=nodeid,
datatype=datatype.pk,
Expand Down

0 comments on commit 7c4087c

Please sign in to comment.