Skip to content

Commit

Permalink
allow log-only behavior for unresolved ids when there are multiple ma…
Browse files Browse the repository at this point in the history
…tches instead of just no matches
  • Loading branch information
jamesturk committed Oct 11, 2016
1 parent 274cd0d commit 0c2cb44
Showing 1 changed file with 10 additions and 7 deletions.
17 changes: 10 additions & 7 deletions pupa/importers/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -144,18 +144,21 @@ def resolve_json_id(self, json_id, allow_no_match=False):
ids = {each.id for each in objects}
if len(ids) == 1:
self.pseudo_id_cache[json_id] = ids.pop()
errmsg = None
elif not ids:
msg = 'cannot resolve pseudo id to {}: {}'.format(
errmsg = 'cannot resolve pseudo id to {}: {}'.format(
self.model_class.__name__, json_id)
else:
errmsg = 'multiple objects returned for {} pseudo id {}: {}'.format(
self.model_class.__name__, json_id, ids)

# either raise or log error
if errmsg:
if not allow_no_match:
raise UnresolvedIdError(msg)
raise UnresolvedIdError(errmsg)
else:
self.error(msg)
self.error(errmsg)
self.pseudo_id_cache[json_id] = None
else:
raise UnresolvedIdError(
'multiple objects returned for {} pseudo id {}: {}'.format(
self.model_class.__name__, json_id, ids))

# return the cached object
return self.pseudo_id_cache[json_id]
Expand Down

0 comments on commit 0c2cb44

Please sign in to comment.