MCPcopy
hub / github.com/sqlalchemy/sqlalchemy / _generate

Method _generate

lib/sqlalchemy/orm/dynamic.py:207–234  ·  view source on GitHub ↗
(
        self,
        sess: Optional[Session] = None,
    )

Source from the content-addressed store, hash-verified

205 return self._generate(sess).count()
206
207 def _generate(
208 self,
209 sess: Optional[Session] = None,
210 ) -> Query[_T]:
211 # note we're returning an entirely new Query class instance
212 # here without any assignment capabilities; the class of this
213 # query is determined by the session.
214 instance = self.instance
215 if sess is None:
216 sess = object_session(instance)
217 if sess is None:
218 raise orm_exc.DetachedInstanceError(
219 "Parent instance %s is not bound to a Session, and no "
220 "contextual session is established; lazy load operation "
221 "of attribute '%s' cannot proceed"
222 % (orm_util.instance_str(instance), self.attr.key)
223 )
224
225 if self.query_class:
226 query = self.query_class(self.attr.target_mapper, session=sess)
227 else:
228 query = sess.query(self.attr.target_mapper)
229
230 query._where_criteria = self._where_criteria
231 query._from_obj = self._from_obj
232 query._order_by_clauses = self._order_by_clauses
233
234 return query
235
236 def add_all(self, iterator: Iterable[_T]) -> None:
237 """Add an iterable of items to this :class:`_orm.AppenderQuery`.

Callers 7

_iterMethod · 0.95
__getitem__Method · 0.95
countMethod · 0.95
_apply_to_parentMethod · 0.45
_setup_orm_returningMethod · 0.45
_cloneMethod · 0.45
set_label_styleMethod · 0.45

Calls 2

object_sessionFunction · 0.85
queryMethod · 0.45

Tested by

no test coverage detected