Skip to content

TupleLoader distinct on all included loaders #324

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 5 additions & 2 deletions gino/loader.py
Original file line number Diff line number Diff line change
Expand Up @@ -163,8 +163,11 @@ def __init__(self, values):
self.loaders = tuple(self.get(value) for value in values)

def do_load(self, row, context):
return tuple(loader.do_load(row, context)[0]
for loader in self.loaders), True
loaders_result = [loader.do_load(row, context) for loader
in self.loaders]
distinct = all(distinct for loader, distinct in loaders_result
if loader is not None)
return tuple([loader for loader, _ in loaders_result]), distinct


class CallableLoader(Loader):
Expand Down
18 changes: 18 additions & 0 deletions tests/test_loader.py
Original file line number Diff line number Diff line change
Expand Up @@ -230,6 +230,24 @@ async def test_distinct_none(bind):
assert not hasattr(u, 'team')


async def test_distinct_tuple_loader(user):
from gino.loader import ColumnLoader

query = db.select([Company,
Team,
db.literal_column("'test'").label('test_column')],
use_labels=True) \
.select_from(Company.outerjoin(Team))

companies = await query.gino.load((
Company.distinct(Company.id).load(add_team=Team.distinct(Team.id)),
ColumnLoader(query.c.test_column)
)).all()
assert len(companies) == 1
assert len(companies[0][0].teams) == 2
assert companies[0][1] == 'test'


async def test_tuple_loader_279(user):
from gino.loader import TupleLoader
query = db.select([User, Team])
Expand Down