Edit:
I’ve just modified the code so to build a string inside the for loop and - at the end of the loop - log that to db.
def get_eids_documenti_archiviati():
log_db('info', 'get_eids_documenti_archiviati - enter')
log_db('info', ' getting documents in database for campaign "{campagna}"'.format(campagna=campagna))
campagna_row = app_tables.configurazione.get(campagna=campagna)
archiviati = app_tables.documenti.search(q.all_of(campagna=campagna_row, envelope_id=q.not_('')))
archived_ids = {}
log_string = ''
for doc_archiviato in archiviati:
log_string += '\n{timestamp}: getting archived IDs for envelope {eid}'.format(timestamp=datetime.now(), eid=doc_archiviato['envelope_id'])
#log_db('info', ' getting archived IDs for envelope {eid}'.format(eid=doc_archiviato['envelope_id']))
archived_ids[doc_archiviato['envelope_id']] = {
'id_pdv_documento': doc_archiviato['id_pdv_documento'],
'id_pdv_audittrail': doc_archiviato['id_pdv_audittrail']
}
log_db('info', log_string)
log_db('debug', repr(archived_ids))
log_db('info', 'get_eids_documenti_archiviati - exit')
return archived_ids
While I think this solves the problem, I feel like I’ve lost something in my logging capabilities.
This way, if there’s a problem, I cannot know what ID was the last before the problem.
Yes I may set up an exception handling inside the for loop so to log to db as last action (will do soon), but nevertheless I feel like now I need to manage by-hand something that “just worked” before.
Can I live with that? Sure!
But to me this is a step backward, not forward.