Repository navigation
fix: keep _default_ when fields() is chained on a QuerySet - #1927
Open
ranjithguggilla wants to merge 1 commit into
Open
ranjithguggilla wants to merge 1 commit into
ranjithguggilla wants to merge 1 commit into
Conversation
QuerySet.fields() built the default token with set(("_default_")), which
is a set of the string's characters. A call such as
server.views.filter(name="x").fields("id") sent
fields=_,a,d,e,f,id,l,t,u instead of fields=_default_,id.
QuerysetEndpoint.fields() already used a one-element tuple, so only the
chained form was affected.
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Motivation
QuerySet.fields()is documented to request_default_plus the fields the caller names. It built that token withset(("_default_")). Those parentheses do not make a tuple, so the value is the set of characters in the string.Calling
fields()on the endpoint is fine.QuerysetEndpoint.fields()already usesset(("_default_",)). The broken call is the one that followsfilter(),order_by(),paginate()orall(), because those return aQuerySetand the next.fields()isQuerySet.fields().I found this while reading
query.py. There is no issue for it. Closed #1620 is a separate report: the server wants_default_first, and this client already sorts the field list.Behavior change
A chained
.fields(...)now sends_default_together with the named fields, the same as calling.fields(...)on the endpoint.CHANGELOG.mdonly points at the Releases page, so there is no Unreleased section to update.Test plan
test_queryset_chained_fieldschecks the set stored on the request options afterfilter(...).fields(...).test_queryset_chained_fields_query_stringchecks thefieldsquery parameter afterorder_by(...).fields(...).pytest teston Python 3.13: 1051 passed, 1 skipped. The same counts were recorded on Python 3.10 and 3.14.black --check --line-length 120and the CImypycommand are clean.