-
Notifications
You must be signed in to change notification settings - Fork 216
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
Add the flat
argument to QueryBuilder.all()
method
#3945
Add the flat
argument to QueryBuilder.all()
method
#3945
Conversation
Codecov Report
@@ Coverage Diff @@
## develop #3945 +/- ##
===========================================
- Coverage 78.31% 78.23% -0.09%
===========================================
Files 461 461
Lines 34082 34067 -15
===========================================
- Hits 26692 26652 -40
- Misses 7390 7415 +25
Continue to review full report at Codecov.
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Small but incredibly useful feature since it is probably the way in which you want the results of the QB for more than 80% of its applications. I only have two small comments/questions but I'll leave the seal of approval since these are very small and maybe don't need changing.
tests/orm/test_querybuilder.py
Outdated
@@ -629,6 +629,32 @@ def test_direction_keyword(self): | |||
res2 = {item[1] for item in qb.all()} | |||
self.assertEqual(res2, {d2.id, d4.id}) | |||
|
|||
@staticmethod | |||
def test_flat(): | |||
"""Test the `flat` keyword for the `.iterall()`, `.all()` and `.one()` methods.""" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Mmm how is this testing .iterall()
and .one()
? Is this some copy/paste leftover?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, this is just a mistake that I left in. I originally thought I was going to implement it for all, but for one
it would break backwards-compatibility and for iterall
it does not make sense
614bbb1
to
03228fe
Compare
@@ -2203,7 +2203,12 @@ def all(self, batch_size=None): | |||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
:param bool flat: | |
Return the result as a flat list of projected entities, | |
with no sub-lists. | |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Apart from that, it looks good to me 👍
@@ -2203,7 +2203,12 @@ def all(self, batch_size=None): | |||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Apart from that, it looks good to me 👍
This allows to simplify the commonly found form: results = [entry[0] for entry in builder.all()] to the more compact and readable form: results = builder.all(flat=True) The default is set to `flat=False` such that this change is fully backwards compatible. Occurrences in the codebase itself have been updated as much as possible.
03228fe
to
fd296ce
Compare
Fixes #3943
This allows to simplify the commonly found form:
to the more compact and readable form:
The default is set to
flat=False
such that this change is fullybackwards compatible. Occurrences in the code base itself have been
updated as much as possible.