--- /dev/null
+.. change::
+ :tags: bug, orm
+ :tickets: 4175
+
+ Fixed bug where the :class:`.Bundle` object did not
+ correctly report upon the primary :class:`.Mapper` object
+ represened by the bundle, if any. An immediate
+ side effect of this issue was that the new selectinload
+ loader strategy wouldn't work with the horizontal sharding
+ extension.
from sqlalchemy.testing import fixtures
from sqlalchemy.testing.engines import testing_engine
from sqlalchemy.testing import eq_
+from sqlalchemy import testing
# TODO: ShardTest can be turned into a base for further subclasses
class DistinctEngineShardTest(ShardTest, fixtures.TestBase):
-
def _init_dbs(self):
db1 = testing_engine('sqlite:///shard1.db',
options=dict(pool_threadlocal=True))
return stmt, params
return db1, db2, db3, db4
+
+
+class SelectinloadRegressionTest(fixtures.DeclarativeMappedTest):
+ @classmethod
+ def setup_classes(cls):
+ Base = cls.DeclarativeBasic
+
+ class Book(Base):
+ __tablename__ = 'book'
+ id = Column(Integer, primary_key=True)
+ pages = relationship('Page')
+
+ class Page(Base):
+ __tablename__ = 'page'
+ id = Column(Integer, primary_key=True)
+ book_id = Column(ForeignKey('book.id'))
+
+ def test_selectinload_query(self):
+ session = ShardedSession(
+ shards={"test": testing.db},
+ shard_chooser=lambda *args: 'test',
+ id_chooser=lambda *args: None,
+ query_chooser=lambda *args: ['test']
+ )
+
+ Book, Page = self.classes("Book", "Page")
+ book = Book()
+ book.pages.append(Page())
+
+ session.add(book)
+ session.commit()
+
+ result = session.query(Book).options(selectinload('pages')).all()
+ eq_(result, [book])
is_(q._mapper_zero(), None)
is_(q._entity_zero(), None)
+ q1 = s.query(Bundle('b1', User.id, User.name))
+ is_(q1._mapper_zero(), inspect(User))
+ is_(q1._entity_zero(), inspect(User))
+
def test_from_statement(self):
User = self.classes.User