| 2857 | raise |
| 2858 | |
| 2859 | def _iter(self) -> Union[ScalarResult[_T], Result[_T]]: |
| 2860 | # new style execution. |
| 2861 | params = self._params |
| 2862 | |
| 2863 | statement = self._statement_20() |
| 2864 | result: Union[ScalarResult[_T], Result[_T]] = self.session.execute( |
| 2865 | statement, |
| 2866 | params, |
| 2867 | execution_options={"_sa_orm_load_options": self.load_options}, |
| 2868 | ) |
| 2869 | |
| 2870 | # legacy: automatically set scalars, unique |
| 2871 | if result._attributes.get("is_single_entity", False): |
| 2872 | result = cast("Result[_T]", result).scalars() |
| 2873 | |
| 2874 | if ( |
| 2875 | result._attributes.get("filtered", False) |
| 2876 | and not self.load_options._yield_per |
| 2877 | ): |
| 2878 | result = result.unique() |
| 2879 | |
| 2880 | return result |
| 2881 | |
| 2882 | def __str__(self) -> str: |
| 2883 | statement = self._statement_20() |