Use first()
function instead of one()
. It will return None if there is no results.
sub_report_id = DBSession.query(TSubReport.ixSubReport).filter(and_(TSubReport.ixSection==sectionID[0], TSubReport.ixReport== reportID[0])).first()
see documentation here