### Description
Fixes: #10933 typing in ColumnExpressionArgument
### Checklist
<!-- go over following points. check them with an `x` if they do apply, (they turn into clickable checkboxes once the PR is submitted, so no need to do everything at once)
-->
This pull request is:
- [ ] A documentation / typographical / small typing error fix
- Good to go, no issue or tests are needed
- [x] A short code fix
- please include the issue number, and create an issue if none exists, which
must include a complete example of the issue. one line code fixes without an
issue and demonstration will not be accepted.
- Please include: `Fixes: #<issue number>` in the commit message
- please include tests. one line code fixes without tests will not be accepted.
- [ ] A new feature implementation
- please include the issue number, and create an issue if none exists, which must
include a complete example of how the feature would look.
- Please include: `Fixes: #<issue number>` in the commit message
- please include tests.
**Have a nice day!**
Closes: #10959
Pull-request: https://github.com/sqlalchemy/sqlalchemy/pull/10959
Pull-request-sha:
6fed2cf1d1ba78e9101a3608bd0cf70f2abb3232
Change-Id: I43420add824881e7cc0ec93e3c8b9a04d33e30df
def with_loader_criteria(
entity_or_base: _EntityType[Any],
- where_criteria: _ColumnExpressionArgument[bool],
+ where_criteria: Union[
+ _ColumnExpressionArgument[bool],
+ Callable[[Any], _ColumnExpressionArgument[bool]],
+ ],
loader_only: bool = False,
include_aliases: bool = False,
propagate_to_loaders: bool = True,
def __init__(
self,
entity_or_base: _EntityType[Any],
- where_criteria: _ColumnExpressionArgument[bool],
+ where_criteria: Union[
+ _ColumnExpressionArgument[bool],
+ Callable[[Any], _ColumnExpressionArgument[bool]],
+ ],
loader_only: bool = False,
include_aliases: bool = False,
propagate_to_loaders: bool = True,
def __init__(
self,
- fn: _LambdaType,
+ fn: _AnyLambdaType,
role: Type[roles.SQLRole],
opts: Union[Type[LambdaOptions], LambdaOptions] = LambdaOptions,
lambda_args: Tuple[Any, ...] = (),
from __future__ import annotations
+from sqlalchemy import ColumnElement
from sqlalchemy import ForeignKey
from sqlalchemy import orm
from sqlalchemy import select
# EXPECTED_MYPY_RE: Argument 1 to .* has incompatible type .*
orm.undefer(B.a).undefer("bar"),
)
+
+
+# test 10959
+def test_10959_with_loader_criteria() -> None:
+ def where_criteria(cls_: type[A]) -> ColumnElement[bool]:
+ return cls_.data == "some data"
+
+ orm.with_loader_criteria(A, lambda cls: cls.data == "some data")
+ orm.with_loader_criteria(A, where_criteria)