--- /dev/null
+.. change::
+ :tags: bug, engine
+ :tickets: 7953
+
+ Fixed issue in :meth:`.Result.columns` method where calling upon
+ :meth:`.Result.columns` with a single index could in some cases,
+ particularly ORM result object cases, cause the :class:`.Result` to yield
+ scalar objects rather than :class:`.Row` objects, as though the
+ :meth:`.Result.scalars` method had been called. In SQLAlchemy 1.4, this
+ scenario emits a warning that the behavior will change in SQLAlchemy 2.0.
self._real_result if self._real_result else cast(Result, self)
)
- if real_result._source_supports_scalars and len(indexes) == 1:
- self._generate_rows = False
- else:
- self._generate_rows = True
+ if not real_result._source_supports_scalars or len(indexes) != 1:
self._metadata = self._metadata._reduce(indexes)
+ assert self._generate_rows
+
return self
@HasMemoized.memoized_attribute
[{"a": 1}, {"a": 2}, {"a": 1}, {"a": 1}, {"a": 4}],
)
+ def test_scalar_mode_columns0_plain(self, no_tuple_fixture):
+ """test #7953"""
+
+ metadata = result.SimpleResultMetaData(["a", "b", "c"])
+
+ r = result.ChunkedIteratorResult(
+ metadata, no_tuple_fixture, source_supports_scalars=True
+ )
+
+ r = r.columns(0)
+ eq_(
+ list(r),
+ [(1,), (2,), (1,), (1,), (4,)],
+ )
+
+ def test_scalar_mode_scalars0(self, no_tuple_fixture):
+ metadata = result.SimpleResultMetaData(["a", "b", "c"])
+
+ r = result.ChunkedIteratorResult(
+ metadata, no_tuple_fixture, source_supports_scalars=True
+ )
+
+ r = r.scalars(0)
+ eq_(
+ list(r),
+ [1, 2, 1, 1, 4],
+ )
+
def test_scalar_mode_but_accessed_nonscalar_result(self, no_tuple_fixture):
metadata = result.SimpleResultMetaData(["a", "b", "c"])