Skip to content

Commit

Permalink
Fix tests
Browse files Browse the repository at this point in the history
  • Loading branch information
ThibaudDauce committed Jun 11, 2024
1 parent 7863547 commit 8290e1f
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 10 deletions.
6 changes: 4 additions & 2 deletions udata/core/dataservices/rdf.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,12 @@
from typing import List, Optional
from rdflib import RDF, Graph

from udata.core.dataservices.models import Dataservice, HarvestMetadata
from udata.core.dataservices.models import Dataservice, HarvestMetadata as HarvestDataserviceMetadata
from udata.core.dataset.models import Dataset, License
from udata.core.dataset.rdf import sanitize_html
from udata.harvest.models import HarvestSource
from udata.rdf import DCAT, DCT, contact_point_from_rdf, rdf_value, theme_labels_from_rdf, themes_from_rdf, url_from_rdf


def dataservice_from_rdf(graph: Graph, dataservice: Dataservice, node, all_datasets: List[Dataset]) -> Dataservice :
'''
Create or update a dataset from a RDF/DCAT graph
Expand Down Expand Up @@ -46,6 +45,9 @@ def dataservice_from_rdf(graph: Graph, dataservice: Dataservice, node, all_datas
if license is not None:
dataservice.license = License.guess(license)

if not harvest:
harvest = HarvestDataserviceMetadata()

dataservice.harvest.created_at = rdf_value(d, DCT.issued)
dataservice.metadata_modified_at = rdf_value(d, DCT.modified)

Expand Down
16 changes: 8 additions & 8 deletions udata/harvest/backends/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -194,9 +194,6 @@ def process_dataset(self, remote_id: str, **kwargs):
if not remote_id:
raise HarvestSkipException("missing identifier")

if not dataset.harvest:
dataset.harvest = HarvestDatasetMetadata()

current_app.logger.addHandler(log_catcher)
dataset = self.inner_process_dataset(item, **kwargs)

Expand Down Expand Up @@ -254,9 +251,6 @@ def process_dataservice(self, remote_id: str, **kwargs) -> bool :
if not remote_id:
raise HarvestSkipException("missing identifier")

if not dataservice.harvest:
dataservice.harvest = HarvestDataserviceMetadata()

dataservice = self.inner_process_dataservice(item, **kwargs)

dataservice.harvest = self.update_dataservice_harvest_info(dataservice.harvest, remote_id)
Expand Down Expand Up @@ -290,7 +284,10 @@ def process_dataservice(self, remote_id: str, **kwargs) -> bool :
item.ended = datetime.utcnow()
self.save_job()

def update_dataset_harvest_info(self, harvest: HarvestDatasetMetadata, remote_id: int):
def update_dataset_harvest_info(self, harvest: Optional[HarvestDatasetMetadata], remote_id: int):
if not harvest:
harvest = HarvestDatasetMetadata()

harvest.backend = self.display_name
harvest.source_id = str(self.source.id)
harvest.remote_id = remote_id
Expand All @@ -303,7 +300,10 @@ def update_dataset_harvest_info(self, harvest: HarvestDatasetMetadata, remote_id

return harvest

def update_dataservice_harvest_info(self, harvest: HarvestDataserviceMetadata, remote_id: int):
def update_dataservice_harvest_info(self, harvest: Optional[HarvestDataserviceMetadata], remote_id: int):
if not harvest:
harvest = HarvestDataserviceMetadata()

harvest.backend = self.display_name
harvest.domain = self.source.domain

Expand Down

0 comments on commit 8290e1f

Please sign in to comment.