MCPcopy
hub / github.com/sqlalchemy/sqlalchemy / _setup_for_recursion

Method _setup_for_recursion

lib/sqlalchemy/orm/strategies.py:1305–1373  ·  view source on GitHub ↗
(self, context, path, loadopt, join_depth=None)

Source from the content-addressed store, hash-verified

1303 __slots__ = ()
1304
1305 def _setup_for_recursion(self, context, path, loadopt, join_depth=None):
1306 effective_path = (
1307 context.compile_state.current_path or orm_util.PathRegistry.root
1308 ) + path
1309
1310 top_level_context = context._get_top_level_context()
1311 execution_options = util.immutabledict(
1312 {"sa_top_level_orm_context": top_level_context}
1313 )
1314
1315 if loadopt:
1316 recursion_depth = loadopt.local_opts.get("recursion_depth", None)
1317 unlimited_recursion = recursion_depth == -1
1318 else:
1319 recursion_depth = None
1320 unlimited_recursion = False
1321
1322 if recursion_depth is not None:
1323 if not self.parent_property._is_self_referential:
1324 raise sa_exc.InvalidRequestError(
1325 f"recursion_depth option on relationship "
1326 f"{self.parent_property} not valid for "
1327 "non-self-referential relationship"
1328 )
1329 recursion_depth = context.execution_options.get(
1330 f"_recursion_depth_{id(self)}", recursion_depth
1331 )
1332
1333 if not unlimited_recursion and recursion_depth < 0:
1334 return (
1335 effective_path,
1336 False,
1337 execution_options,
1338 recursion_depth,
1339 )
1340
1341 if not unlimited_recursion:
1342 execution_options = execution_options.union(
1343 {
1344 f"_recursion_depth_{id(self)}": recursion_depth - 1,
1345 }
1346 )
1347
1348 if loading._PostLoad.path_exists(
1349 context, effective_path, self.parent_property
1350 ):
1351 return effective_path, False, execution_options, recursion_depth
1352
1353 path_w_prop = path[self.parent_property]
1354 effective_path_w_prop = effective_path[self.parent_property]
1355
1356 if not path_w_prop.contains(context.attributes, "loader"):
1357 if join_depth:
1358 if effective_path_w_prop.length / 2 > join_depth:
1359 return (
1360 effective_path,
1361 False,
1362 execution_options,

Callers 3

create_row_processorMethod · 0.80
create_row_processorMethod · 0.80
create_row_processorMethod · 0.80

Calls 6

contains_mapperMethod · 0.80
getMethod · 0.45
unionMethod · 0.45
path_existsMethod · 0.45
containsMethod · 0.45

Tested by

no test coverage detected