(
self,
sess: Optional[Session] = None,
)
| 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`. |
no test coverage detected