Used by per-state lazy loaders to add options to the "lazy load" query from a parent query. Creates a cache key based on given load path and query options; if a repeatable cache key cannot be generated, the query is "spoiled" so that it won't use caching.
(self, options, effective_path, cache_path=None)
| 177 | return q |
| 178 | |
| 179 | def _add_lazyload_options(self, options, effective_path, cache_path=None): |
| 180 | """Used by per-state lazy loaders to add options to the |
| 181 | "lazy load" query from a parent query. |
| 182 | |
| 183 | Creates a cache key based on given load path and query options; |
| 184 | if a repeatable cache key cannot be generated, the query is |
| 185 | "spoiled" so that it won't use caching. |
| 186 | |
| 187 | """ |
| 188 | |
| 189 | key = () |
| 190 | |
| 191 | if not cache_path: |
| 192 | cache_path = effective_path |
| 193 | |
| 194 | for opt in options: |
| 195 | if opt._is_legacy_option or opt._is_compile_state: |
| 196 | ck = opt._generate_cache_key() |
| 197 | if ck is None: |
| 198 | self.spoil(full=True) |
| 199 | else: |
| 200 | assert not ck[1], ( |
| 201 | "loader options with variable bound parameters " |
| 202 | "not supported with baked queries. Please " |
| 203 | "use new-style select() statements for cached " |
| 204 | "ORM queries." |
| 205 | ) |
| 206 | key += ck[0] |
| 207 | |
| 208 | self.add_criteria( |
| 209 | lambda q: q._with_current_path(effective_path).options(*options), |
| 210 | cache_path.path, |
| 211 | key, |
| 212 | ) |
| 213 | |
| 214 | def _retrieve_baked_query(self, session): |
| 215 | query = self._bakery.get(self._effective_key(session), None) |
no test coverage detected