class_docstr: A mixin that expects to be mixing in a Query class with
  AbstractAppender.
class_docstr_tok: ["A","mixin","that","expects","to","be","mixing","in","a","Query","class","with","AbstractAppender","."]
code: def _generate(
      self,
      sess: Optional[Session] = None,
  ) -> Query[_T]:
      # note we're returning an entirely new Query class instance
      # here without any assignment capabilities; the class of this
      # query is determined by the session.
      instance = self.instance
      if sess is None:
          sess = object_session(instance)
          if sess is None:
              raise orm_exc.DetachedInstanceError(
                  "Parent instance %s is not bound to a Session, and no "
                  "contextual session is established; lazy load operation "
                  "of attribute '%s' cannot proceed"
                  % (orm_util.instance_str(instance), self.attr.key)
              )
  
      if self.query_class:
          query = self.query_class(
              self.attr.target_mapper, session=sess
          )
      else:
          query = sess.query(self.attr.target_mapper)
  
      query._where_criteria = self._where_criteria
      query._from_obj = self._from_obj
      query._order_by_clauses = self._order_by_clauses
  
      return query
  
imports: from __future__ import annotations
  from typing import Any
  from typing import Iterable
  from typing import Iterator
  from typing import List
  from typing import Optional
  from typing import Tuple
  from typing import Type
  from typing import TYPE_CHECKING
  from typing import TypeVar
  from typing import Union
  from .None import attributes
  from .None import exc
  from .None import relationships
  from .None import util
  from .base import PassiveFlag
  from .query import Query
  from .session import object_session
  from .writeonly import AbstractCollectionWriter
  from .writeonly import WriteOnlyAttributeImpl
  from .writeonly import WriteOnlyHistory
  from .writeonly import WriteOnlyLoader
  from ..None import util
  from ..engine import result
label_desc: Use image node_id 7 for calling the AppenderMixin obj's underlying member method code with example usage: obj._generate(sess) and returns: query