else:
self.label_style = self.select_statement._label_style
- self._label_convention = self._column_naming_convention(
- statement._label_style, self.use_legacy_query_style
- )
-
if select_statement._memoized_select_entities:
self._memoized_entities = {
memoized_entities: _QueryEntity.to_compile_state(
)
}
+ # label_convention is stateful and will yield deduping keys if it
+ # sees the same key twice. therefore it's important that it is not
+ # invoked for the above "memoized" entities that aren't actually
+ # in the columns clause
+ self._label_convention = self._column_naming_convention(
+ statement._label_style, self.use_legacy_query_style
+ )
+
_QueryEntity.to_compile_state(
self,
select_statement._raw_columns,
entity._select_iterable,
entities_collection,
idx,
+ is_current_entities,
)
else:
if entity._annotations.get("bundle", False):
_BundleEntity(
- compile_state, entity, entities_collection
+ compile_state,
+ entity,
+ entities_collection,
+ is_current_entities,
)
elif entity._is_clause_list:
# this is legacy only - test_composites.py
entity._select_iterable,
entities_collection,
idx,
+ is_current_entities,
)
else:
_ColumnEntity._for_columns(
- compile_state, [entity], entities_collection, idx
+ compile_state,
+ [entity],
+ entities_collection,
+ idx,
+ is_current_entities,
)
elif entity.is_bundle:
_BundleEntity(compile_state, entity, entities_collection)
compile_state,
expr,
entities_collection,
+ is_current_entities,
setup_entities=True,
parent_bundle=None,
):
compile_state,
expr,
entities_collection,
+ is_current_entities,
parent_bundle=self,
)
elif isinstance(expr, Bundle):
compile_state,
expr,
entities_collection,
+ is_current_entities,
parent_bundle=self,
)
else:
[expr],
entities_collection,
None,
+ is_current_entities,
parent_bundle=self,
)
columns,
entities_collection,
raw_column_index,
+ is_current_entities,
parent_bundle=None,
):
for column in columns:
entities_collection,
_entity,
raw_column_index,
+ is_current_entities,
parent_bundle=parent_bundle,
)
else:
entities_collection,
_entity,
raw_column_index,
+ is_current_entities,
parent_bundle=parent_bundle,
)
else:
column,
entities_collection,
raw_column_index,
+ is_current_entities,
parent_bundle=parent_bundle,
)
column,
entities_collection,
raw_column_index,
+ is_current_entities,
parent_bundle=None,
):
self.expr = column
self.raw_column_index = raw_column_index
self.translate_raw_column = raw_column_index is not None
- if column._is_text_clause:
+
+ if not is_current_entities or column._is_text_clause:
self._label_name = None
else:
self._label_name = compile_state._label_convention(column)
entities_collection,
parententity,
raw_column_index,
+ is_current_entities,
parent_bundle=None,
):
annotations = column._annotations
self.translate_raw_column = raw_column_index is not None
self.raw_column_index = raw_column_index
- self._label_name = compile_state._label_convention(
- column, col_name=orm_key
- )
+
+ if is_current_entities:
+ self._label_name = compile_state._label_convention(
+ column, col_name=orm_key
+ )
+ else:
+ self._label_name = None
_entity._post_inspect
self.entity_zero = self.entity_zero_or_selectable = ezero = _entity
from sqlalchemy.orm import attributes
from sqlalchemy.orm import backref
from sqlalchemy.orm import Bundle
-from sqlalchemy.orm import clear_mappers
from sqlalchemy.orm import column_property
from sqlalchemy.orm import contains_eager
from sqlalchemy.orm import defer
assert_row_keys(stmt, expected, coreorm_exec)
+ def test_with_only_columns(self, assert_row_keys):
+ """test #8001"""
+
+ User, Address = self.classes("User", "Address")
+
+ stmt = select(User.id, Address.email_address).join_from(User, Address)
+ stmt = stmt.with_only_columns(
+ stmt.selected_columns.id, stmt.selected_columns.email_address
+ )
+
+ assert_row_keys(stmt, ["id", "email_address"], "orm")
+
def test_explicit_cols_legacy(self):
User = self.classes.User
eq_(row._mapping.keys(), ["id", "name", "id", "name"])
@testing.fixture
- def uname_fixture(self):
+ def uname_fixture(self, registry):
class Foo:
pass
- if False:
- # this conditional creates the table each time which would
- # eliminate cross-test memoization issues. if the tests
- # are failing without this then there's a memoization issue.
- # check AnnotatedColumn memoized keys
- m = MetaData()
- users = Table(
- "users",
- m,
- Column("id", Integer, primary_key=True),
- Column(
- "name",
- String,
- ),
- )
- self.mapper_registry.map_imperatively(
- Foo, users, properties={"uname": users.c.name}
- )
- else:
- users = self.tables.users
- clear_mappers()
- self.mapper_registry.map_imperatively(
- Foo, users, properties={"uname": users.c.name}
- )
+ users = self.tables.users
+ registry.map_imperatively(
+ Foo, users, properties={"uname": users.c.name}
+ )
return Foo