| 2914 | raise |
| 2915 | |
| 2916 | def _iter(self) -> Union[ScalarResult[_T], Result[_T]]: |
| 2917 | # new style execution. |
| 2918 | params = self._params |
| 2919 | |
| 2920 | statement = self._statement_20() |
| 2921 | result: Union[ScalarResult[_T], Result[_T]] = self.session.execute( |
| 2922 | statement, |
| 2923 | params, |
| 2924 | execution_options={"_sa_orm_load_options": self.load_options}, |
| 2925 | ) |
| 2926 | |
| 2927 | # legacy: automatically set scalars, unique |
| 2928 | if result._attributes.get("is_single_entity", False): |
| 2929 | result = cast("Result[_T]", result).scalars() |
| 2930 | |
| 2931 | if ( |
| 2932 | result._attributes.get("filtered", False) |
| 2933 | and not self.load_options._yield_per |
| 2934 | ): |
| 2935 | result = result.unique() |
| 2936 | |
| 2937 | return result |
| 2938 | |
| 2939 | def __str__(self) -> str: |
| 2940 | statement = self._statement_20() |