python - check if .one() is empty sqlAlchemy -


I am running queries based on other IDs for queries. The problem I have is that sometimes the query will not get results. Instead of having the whole program crash, how can I see if there will be no result?

This is my query:

  sub_report_id = DBSession.query (TSubReport.ixSubReport) .filters (and_ (TSubReport.ixSection == SectionID [0], TSubReport. ixReport == Riportaidi [0]). a ()  

when code gets executed and no results were found, I get Noarsltfound exception

  NoResultFound: No row found for one  

There is just one way to leave, is there any outcome?

SO Found solution on

) If no results, no one will return.

  sub_report_id = DBSession.query (TSubReport.ixSubReport) .filter (and_ (TSubReport.ixSection == SectionID [0], TSubReport.ixReport == ReportID [0]).) First ()  

view the documentation