title: Cannot Resolve a 500 (Internal Server Error) Code
body: <p>I have run into a 500 error that I cannot resolve while practicing with making a To Do app with various lists &amp; to do items that all have full CRUD options.</p>
  
  <p>To Do List code:</p>
  
  <pre><code>class TodoList (db.Model):
      __tablename__ = 'todolists'
      id = db.Column(db.Integer, primary_key=True)
      name = db.Column(db.String(), nullable=False)
      todos = db.relationship('Todo', backref='list', lazy=True)
  
  const todo_list_input = document.getElementById('todo_list_id');
              document.getElementById('create_list_box_button').onsubmit = function(e) {
                  e.preventDefault();
                  const list_title = todo_list_input.value;
                  todo_list_input.value = '';
                  fetch('/todolists/create', {
                      method: 'POST',
                      body: JSON.stringify({
                          'todo_list_id': list_title,
                      }),
                      headers: {
                          'Contet-Type': 'application/json'
                      }
                  })
                  .then(response =&gt; response.json())
                  .then(jsonResponse =&gt; {
                      const li = document.createElement('li');
                      const checkbox = document.createElement('input');
                      checkbox.className = 'check-completed';
                      checkbox.type = 'checkbox';
                      checkbox.setAttribute('data-id', jsonResponse.id);
                      li.appendChild(checkbox);
  
                      const text = document.createTextNode(' ' + jsonResponse.description);
                      li.appendChild(text);
  
                      const deleteButton = document.createElement('button');
                      deleteButton.className = 'delete-button';
                      deleteButton.setAttribute('data-id', jsonResponse.id);
                      deleteButton.innerHTML = '&amp;cross;';
                      li.appendChild(deleteButton);
  
                      document.getElementById('todo_lists_buttons').appendChild(li);
                      document.getElementById('error').className = 'hidden';
  
                  })
                  .catch(function() {
                      console.error('Error occurred');
                      document.getElementById('error').className = '';
                  })
              }
  
  
  @app.route('/todolists/create', methods=['POST'])
  def create_todoList():
      error = False
      body = {}
      try:
          list_name = request.json()['list_name']
          todoList = List(list_name=list_name)
          db.session.add(todoList)
          db.session.commit()
          body['list_name'] = todoList.list_name
      except:
          error = True
          db.session.rollback()
          print(sys.exc_info())
      finally:
          db.session.close()
      if not error:
          return jsonify(body)
      else:
          abort(500)
  </code></pre>
  
  <p>I've tried changing variable names around throughout, no joy there, as well as a few other things to try to pinpoint the issue and am just out of ideas (still new at this) on what might be going on.</p>
  
  <p>This only occurs when attempting to 'Create' a new To Do List. I can swap between lists and create/delete To Do Items no problem, it's just the Create List that isn't working.</p>
  
  <p>To Do item code:</p>
  
  <pre><code>class Todo(db.Model):
      __tablename__ = 'todos'
      id = db.Column(db.Integer, primary_key=True)
      description = db.Column(db.String(), nullable=False)
      completed = db.Column(db.Boolean, default=False)
      list_id = db.Column(db.Integer, db.ForeignKey('todolists.id'), nullable=False)
  
  const todo_item_input = document.getElementById('description');
              document.getElementById('create_todo_box_button').onsubmit = function(e) {
                  e.preventDefault();
                  const desc = todo_item_input.value;
                  todo_item_input.value = '';
                  fetch('/todos/create', {
                      method: 'POST',
                      body: JSON.stringify({
                          'description': desc,
                          'list_id': {{ active_list.id }}
                      }),
                      headers: {
                          'Content-Type': 'application/json'
                      }
                  })
                  .then(response =&gt; response.json())
                  .then(jsonResponse =&gt; {
                      const li = document.createElement('li');
                      const checkbox = document.createElement('input');
                      checkbox.className = 'check-completed';
                      checkbox.type = 'checkbox';
                      checkbox.setAttribute('data-id', jsonResponse.id);
                      li.appendChild(checkbox);
  
                      const text = document.createTextNode(' ' + jsonResponse.description);
                      li.appendChild(text);
  
                      const deleteButton = document.createElement('button');
                      deleteButton.className = 'delete-button';
                      deleteButton.setAttribute('data-id', jsonResponse.id);
                      deleteButton.innerHTML = '&amp;cross;';
  
                      li.appendChild(deleteButton);
  
                      document.getElementById('todos').appendChild(li);
  
                      document.getElementById('error').className = 'hidden';
                  })
                  .catch(function() {
                      console.error('Error occured');
                      document.getElementById('error').className = '';
                  })
              }
  
  @app.route('/todos/create', methods=['POST'])
  def create_todo():
      error = False
      body = {}
      try:
          description = request.get_json()['description']
          list_id = request.get_json()['list_id']
          todo = Todo(description=description)
          active_list = TodoList.query.get(list_id)
          todo.list = active_list
          db.session.add(todo)
          db.session.commit()
          body['description'] = todo.description
      except:
          error = True
          db.session.rollback()
          print(sys.exc_info())
      finally:
          db.session.close()
      if not error:
          return jsonify(body)
      else:
          abort(500)
  </code></pre>
  
  <p><a href="https://i.stack.imgur.com/y3qeI.png" rel="nofollow noreferrer">Web app view</a>
  <a href="https://i.stack.imgur.com/U7FXi.png" rel="nofollow noreferrer">Error</a></p>