docs: def _session_for(self, model_or_session):
          """Return session instance for object parameter.
  
          If parameter is a session instance, it is return as is.
          If parameter is a registered model instance, its session will be used.
  
          If parameter is a detached model instance, or None, application scoped
          session will be used (db.session())
  
          If parameter is a scoped_session instance, a new session will be
          instanciated.
          """
          session = model_or_session
          if not isinstance(session, (Session, sa.orm.scoped_session)):
              if session is not None:
                  session = sa.orm.object_session(model_or_session)
  
              if session is None:
                  session = db.session
  
          if isinstance(session, sa.orm.scoped_session):
              session = session()
  
          return session