| 1367 | return newcol |
| 1368 | |
| 1369 | def _locate_col( |
| 1370 | self, col: ColumnElement[Any] |
| 1371 | ) -> Optional[ColumnElement[Any]]: |
| 1372 | # both replace and traverse() are overly complicated for what |
| 1373 | # we are doing here and we would do better to have an inlined |
| 1374 | # version that doesn't build up as much overhead. the issue is that |
| 1375 | # sometimes the lookup does in fact have to adapt the insides of |
| 1376 | # say a labeled scalar subquery. However, if the object is an |
| 1377 | # Immutable, i.e. Column objects, we can skip the "clone" / |
| 1378 | # "copy internals" part since those will be no-ops in any case. |
| 1379 | # additionally we want to catch singleton objects null/true/false |
| 1380 | # and make sure they are adapted as well here. |
| 1381 | |
| 1382 | if col._is_immutable: |
| 1383 | for vis in self.visitor_iterator: |
| 1384 | c = vis.replace(col, _include_singleton_constants=True) |
| 1385 | if c is not None: |
| 1386 | break |
| 1387 | else: |
| 1388 | c = col |
| 1389 | else: |
| 1390 | c = ClauseAdapter.traverse(self, col) |
| 1391 | |
| 1392 | if self._wrap: |
| 1393 | c2 = self._wrap._locate_col(c) |
| 1394 | if c2 is not None: |
| 1395 | c = c2 |
| 1396 | |
| 1397 | if self.adapt_required and c is col: |
| 1398 | return None |
| 1399 | |
| 1400 | # allow_label_resolve is consumed by one case for joined eager loading |
| 1401 | # as part of its logic to prevent its own columns from being affected |
| 1402 | # by .order_by(). Before full typing were applied to the ORM, this |
| 1403 | # logic would set this attribute on the incoming object (which is |
| 1404 | # typically a column, but we have a test for it being a non-column |
| 1405 | # object) if no column were found. While this seemed to |
| 1406 | # have no negative effects, this adjustment should only occur on the |
| 1407 | # new column which is assumed to be local to an adapted selectable. |
| 1408 | if c is not col: |
| 1409 | c._allow_label_resolve = self.allow_label_resolve |
| 1410 | |
| 1411 | return c |
| 1412 | |
| 1413 | |
| 1414 | def _offset_or_limit_clause( |