From 74633d080373e89335ee791878eadc023c9bde38 Mon Sep 17 00:00:00 2001 From: amercader Date: Wed, 6 Mar 2013 13:44:04 +0000 Subject: [PATCH] Fix error count in job stats We want to take into account objects with errors that where created or updated anyway (eg bbox errors), so we bascially query for the number of objects that have object errors. Also add the number of gather errors to this count. --- ckanext/harvest/logic/dictization.py | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/ckanext/harvest/logic/dictization.py b/ckanext/harvest/logic/dictization.py index 6c6f182..cbf204a 100644 --- a/ckanext/harvest/logic/dictization.py +++ b/ckanext/harvest/logic/dictization.py @@ -37,6 +37,22 @@ def harvest_job_dictize(job, context): for status, count in stats: out['stats'][status] = count + # We actually want to check which objects had errors, because they + # could have been added/updated anyway (eg bbox errors) + count = model.Session.query(func.distinct(HarvestObjectError.harvest_object_id)) \ + .join(HarvestObject) \ + .filter(HarvestObject.harvest_job_id==job.id) \ + .count() + if count > 0: + out['stats']['errored'] = count + + # Add gather errors to the error count + count = model.Session.query(HarvestGatherError) \ + .filter(HarvestGatherError.harvest_job_id==job.id) \ + .count() + if count > 0: + out['stats']['errored'] = out['stats'].get('errored', 0) + count + if context.get('return_error_summary', True): q = model.Session.query(HarvestObjectError.message, \ func.count(HarvestObjectError.message).label('error_count')) \