title: internal server error Flask - Python
body: <p>This is my code in Python - Flask. Here I am entering data for a Theatre (Theatre table) and then fetching the respective id and then adding the screen to the respective theatre_id in the Screen table.</p>
  
  <p>The problem is Theatre gets added to the database and I am able to fetch the id. The code for Screen doesn't seem to work (for loop does work if I comment out the session.screen add and commit statement)
  And even the rollback doesn't happen if screen commit doesn't happen.</p>
  
  <pre><code>session_theatre = Session_theatre()
  session_screen = Session_screen()
  id = 1
  if request.method == "POST":
      if form.validate_on_submit():
          name = str(form.name.data)
          city = str(form.location.data)
          address = str(form.address.data)
          no_of_screen = int(form.total_no_screen.data)
          if (name !="" and name!=" " and city != "" and city != " " and address != ""and address != " " and no_of_screen != None):
              t = Theatre(name,city,address,1)
              try:
                  session_theatre.add(t)
                  session_theatre.commit()
                  query = session_theatre.query(Theatre).filter_by(name=name,city =city).all()
                  for i in query :
                      id = i
                  for i in range (0,no_of_screen):
                      flash(id)
                      screen = Screen(str(i+1),1,20,1,20,id)
                      session_screen.add(screen)
                      session_screen.commit()
                  flash("Successfully added !!")
              except :
                  session_screen.rollback()
                  session_theatre.rollback()
                  flash("Oops something went wrong !!")
              finally:
                  session_screen.close()
                  session_theatre.close()
          else :
              flash("Please fill the input")
  return render_template('admin/add_theatre.html',form = form)
  </code></pre>
  
  <p>Screen Model</p>
  
  <pre><code>class Screen(db.Model):
      __tablename__ = "screens"
      id = db.Column(db.Integer,primary_key=True)
      screen_num = db.Column(db.String(1))
      seat_row_start = db.Column(db.Integer)
      seat_row_end = db.Column(db.Integer)
      seat_col_start = db.Column(db.Integer)
      seat_col_end = db.Column(db.Integer)
      theatre_id =  db.Column(db.Integer, db.ForeignKey('theatres.id'))
  
      def __init__(self, screen_num, 
      seat_row_start,seat_row_end,seat_col_start,seat_col_end,theatre_id):
          self.screen_num = screen_num
          self.seat_row_start = seat_row_start
          self.seat_row_end = seat_row_end
          self.seat_col_start = seat_col_start
          self.seat_col_end = seat_col_end
          self.theatre_id = theatre_id
  </code></pre>