code: def _record_ops(session: Session, **kwargs: t.Any) -> None:
      if not has_app_context():
          return
  
      if not current_app.config["SQLALCHEMY_TRACK_MODIFICATIONS"]:
          return
  
      for targets, operation in (
          (session.new, "insert"),
          (session.dirty, "update"),
          (session.deleted, "delete"),
      ):
          for target in targets:
              state = sa.inspect(target)
              key = (
                  state.identity_key
                  if state.has_identity
                  else id(target)
              )
              session._model_changes[key] = (target, operation)
  
file_path: flask-sqlalchemy/src/flask_sqlalchemy/track_modifications.py
imports: from __future__ import annotations
  import typing
  import sqlalchemy
  import sqlalchemy.event
  import sqlalchemy.orm
  from flask import current_app
  from flask import has_app_context
  from flask.signals import Namespace
label_desc: Use image node_id 2 for calling a global function with example usage: _record_ops(session) without return types