class_docstr: A SQLAlchemy :class:`~sqlalchemy.orm.Session` class that chooses what engine to
  use based on the bind key associated with the metadata associated with the thing
  being queried.
  
  To customize ``db.session``, subclass this and pass it as the ``class_`` key in the
  ``session_options`` to :class:`.SQLAlchemy`.
  
  .. versionchanged:: 3.0
      Renamed from ``SignallingSession``.
class_docstr_tok: ["A","SQLAlchemy",":","class",":","`","~sqlalchemy.orm.Session","`","class","that","chooses","what","engine","to","use","based","on","the","bind","key","associated","with","the","metadata","associated","with","the","thing","being","queried",".","To","customize","``","db.session","``",",","subclass","this","and","pass","it","as","the","``","class_","``","key","in","the","``","session_options","``","to",":","class",":","`",".SQLAlchemy","`",".","..","versionchanged",":",":","3.0","Renamed","from","``","SignallingSession","``","."]
docstr: Select an engine based on the ``bind_key`` of the metadata associated with
  the model or table being queried. If no bind key is set, uses the default bind.
  
  .. versionchanged:: 3.0.3
      Fix finding the bind for a joined inheritance model.
  
  .. versionchanged:: 3.0
      The implementation more closely matches the base SQLAlchemy implementation.
  
  .. versionchanged:: 2.1
      Support joining an external transaction.
docstr_tok: ["Select","an","engine","based","on","the","``","bind_key","``","of","the","metadata","associated","with","the","model","or","table","being","queried",".","If","no","bind","key","is","set",",","uses","the","default","bind",".","..","versionchanged",":",":","3.0.3","Fix","finding","the","bind","for","a","joined","inheritance","model",".","..","versionchanged",":",":","3.0","The","implementation","more","closely","matches","the","base","SQLAlchemy","implementation",".","..","versionchanged",":",":","2.1","Support","joining","an","external","transaction","."]
code: def get_bind(
      self,
      mapper: t.Any | None = None,
      clause: t.Any | None = None,
      bind: sa.engine.Engine | sa.engine.Connection | None = None,
      **kwargs: t.Any,
  ) -> sa.engine.Engine | sa.engine.Connection:
      """Select an engine based on the ``bind_key`` of the metadata associated with
      the model or table being queried. If no bind key is set, uses the default bind.
  
      .. versionchanged:: 3.0.3
          Fix finding the bind for a joined inheritance model.
  
      .. versionchanged:: 3.0
          The implementation more closely matches the base SQLAlchemy implementation.
  
      .. versionchanged:: 2.1
          Support joining an external transaction.
      """
      if bind is not None:
          return bind
  
      engines = self._db.engines
  
      if mapper is not None:
          try:
              mapper = sa.inspect(mapper)
          except sa_exc.NoInspectionAvailable as e:
              if isinstance(mapper, type):
                  raise sa_orm.exc.UnmappedClassError(mapper) from e
  
              raise
  
          engine = _clause_to_engine(mapper.local_table, engines)
  
          if engine is not None:
              return engine
  
      if clause is not None:
          engine = _clause_to_engine(clause, engines)
  
          if engine is not None:
              return engine
  
      if None in engines:
          return engines[None]
  
      return super().get_bind(
          mapper=mapper, clause=clause, bind=bind, **kwargs
      )
  
file_path: flask-sqlalchemy/src/flask_sqlalchemy/session.py
imports: from __future__ import annotations
  import typing
  import sqlalchemy
  import sqlalchemy.exc
  import sqlalchemy.orm
  from flask.globals import app_ctx
label_desc: Use image node_id 2 for calling the Session obj's underlying member method code with example usage: obj.get_bind(mapper, clause, bind) and returns: super, bind, engines, engine, engine