Instead of these 2 lines, try this:
```Event.query.get(event_id) 
if event is not None:
  ...```