title: Idle database connections in Django
body: <p>In Django,
  how do I make my code recover from a database connection which is dead ?
  This is the scenario:</p>
  
  <pre><code># requests enters view handler
  
  # executes code which does some synchronous tasks without any database interaction for 15min.
  
  # first database activity in this request after 15min.
  try:
     o, created = act_details.objects.get_or_create(id=1) # this line fails because of a dead database connection.
  
  except Exception as e:
     logger.error(e) # ORA-03114: not connected to ORACLE
  </code></pre>
  
  <p>Assuming I handle the exception, is there a way to put things back on track by creating a new database connection in the exception block ?</p>
  
  <p>My issue is similar to <a href="https://stackoverflow.com/questions/28720874/recover-from-dead-database-connection-in-django">Recover from dead database connection in Django</a> but different because the connections I use are entirely framework managed.</p>
  
  <p>This issue happens <em>only</em> when the remote server/network/firewall drops idle connections. </p>