Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 13 additions & 4 deletions core/importers/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -573,12 +573,17 @@ def get_queryset(self): # pylint: disable=too-many-branches
if self.queryset:
return self.queryset

parent_uri = f'/{"users" if self.is_user_owner() else "orgs"}/{self.get("owner")}/sources/{self.get("source")}/'
if self.get('id'):
self.queryset = Mapping.objects.filter(
parent__uri=parent_uri, id=F('versioned_object_id'), mnemonic=self.get('id'))
return self.queryset
Comment thread
filiperochalopes marked this conversation as resolved.
Resolved
Comment thread
filiperochalopes marked this conversation as resolved.
Resolved

from_concept_url = self.get('from_concept_url')
to_concept_url = self.get('to_concept_url')
to_concept_code = self.get('to_concept_code')
from_concept_code = self.get('from_concept_code')
to_source_url = self.get('to_source_url')
parent_uri = f'/{"users" if self.is_user_owner() else "orgs"}/{self.get("owner")}/sources/{self.get("source")}/'
filters = {
'parent__uri': parent_uri,
'id': F('versioned_object_id'),
Expand Down Expand Up @@ -607,9 +612,6 @@ def get_queryset(self): # pylint: disable=too-many-branches
if self.get_cached_source_exists_by_uri(drop_version(to_source_uri)):
filters['to_source__uri'] = to_source_uri

if self.get('id'):
filters['mnemonic'] = self.get('id')

if to_source_url:
to_source_uri = drop_version(to_source_url)
filters['to_source_url'] = to_source_uri
Expand Down Expand Up @@ -663,7 +665,12 @@ def process(self):
self.instance = queryset.first().clone()
self.instance._counted = None # pylint: disable=protected-access
self.instance._index = False # pylint: disable=protected-access
previous_from_concept_id = self.instance.from_concept_id if (
self.instance.from_source_id == self.instance.parent_id) else None
errors = Mapping.create_new_version_for(self.instance, self.data, self.user, cache=self.cache)
if previous_from_concept_id and previous_from_concept_id != self.instance.from_concept_id:
# the mapping moved to another from concept, whose mapped codes then need a refresh
self.instance.replaced_from_concept_id = previous_from_concept_id
if errors and Mapping.is_standard_checksum_error(errors):
return UNCHANGED
return errors or UPDATED
Expand Down Expand Up @@ -821,6 +828,8 @@ def add(self, instance):
]))
if resource == 'mapping' and instance.from_concept_id and instance.from_source_id == instance.parent_id:
self.mapped_concept_ids.add(instance.from_concept_id)
if resource == 'mapping' and get(instance, 'replaced_from_concept_id'):
self.mapped_concept_ids.add(instance.replaced_from_concept_id) # the mapping no longer starts there

def finish(self):
# every row first, so that a failure to queue can't leave any deferred
Expand Down
Loading
Loading