def get_instance(cls, instance_or_pk):
        """Return a model instance in ``db.session``.

        :param instance_or_pk: An instance of this model class, or a
          primary key. A composite primary key can be passed as a
          tuple.

        Example::

          @db.atomic
          def increase_account_balance(account, amount):
              # Here `Account` is a subclass of `db.Model`.
              account = Account.get_instance(account)
              account.balance += amount

          # Now `increase_account_balance` can be
          # called with an account instance:
          increase_account_balance(my_account, 100.00)

          # or with an account primary key (1234):
          increase_account_balance(1234, 100.00)

        """

        if isinstance(instance_or_pk, cls):
            if instance_or_pk in cls._flask_signalbus_sa.session:
                return instance_or_pk
            instance_or_pk = inspect(cls).primary_key_from_instance(instance_or_pk)
        return cls.query.get(instance_or_pk)
def get_instance ( cls , instance_or_pk ) : if isinstance ( instance_or_pk , cls ) : if instance_or_pk in cls . _flask_signalbus_sa . session : return instance_or_pk instance_or_pk = inspect ( cls ) . primary_key_from_instance ( instance_or_pk ) return cls . query . get ( instance_or_pk )
Return a model instance in ``db.session``.

        :param instance_or_pk: An instance of this model class, or a
          primary key. A composite primary key can be passed as a
          tuple.

        Example::

          @db.atomic
          def increase_account_balance(account, amount):
              # Here `Account` is a subclass of `db.Model`.
              account = Account.get_instance(account)
              account.balance += amount

          # Now `increase_account_balance` can be
          # called with an account instance:
          increase_account_balance(my_account, 100.00)

          # or with an account primary key (1234):
          increase_account_balance(1234, 100.00)