My Flask app reads time-based CSV log file of observations where new entries are appended. My approach in aim to avoid duplications is to collect variables and test before adding the record as in:
sl = db.session.query(DesignObservation).filter_by(worker_id = worker_id).filter_by(design_id = design_id).filter_by(ob_date = ob_date)
if len(sl.all()):
pass
else:
db.session.add(observation_record)
db.session.commit()
Not sure why this pattern does not add the record. If I forgo the test the record adds but dups would be added on subsequent runs.