fix(query_builder): don't explode plucked scalars on masked doctypes#1
Merged
pipech merged 2 commits intoJun 11, 2026
Conversation
`execute_query` runs `mask_fields()` on every result whenever the queried
doctype has masked fields for the current (non-admin) user. With `pluck=True`
the DB layer has already reduced each row to a scalar, so the result is a flat
list of values rather than rows. `mask_list_results` then ran `list(row)` on
each scalar, turning "P-1156" into `('P', '-', '1', '1', '5', '6')` for strings
and raising `TypeError: 'int' object is not iterable` for numeric fields.
Handle `pluck` explicitly: mask each scalar only when the plucked field is
itself a masked field, otherwise return the value untouched. Admin users were
never affected since `get_masked_fields()` returns nothing for them.
Fixes frappe#39898
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
pipech
reviewed
Jun 11, 2026
Address review feedback on frappe#39898: annotate the helper's arguments and return type, matching the style of mask_fields(). Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
spc-agent-00
added a commit
that referenced
this pull request
Jun 15, 2026
DatabaseQuery.execute returned the plucked scalar list before running mask_fields, so a masked field leaked its raw value for non-admin users when callers asked for a flat pluck list. Mask the dict rows first, then pluck, reusing the existing mask_dict_results path. This is the legacy db_query counterpart to the query-builder pluck fix in #1. No core caller routes pluck through this engine on 16.12.2 (get_list/get_all/reportview use qb_query), so this covers direct DatabaseQuery callers and any code still on the legacy path. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
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.
Problem
Fixes frappe#39898
For non-admin users,
frappe.db.get_values(..., pluck=True)returns corrupted data when the queried doctype has a masked field — instead of a list of strings it returns a list of per-character tuples:For numeric plucked fields it was worse — it raised
TypeError: 'int' object is not iterable.Root cause
query_builder/utils.py::execute_query()runsmask_fields()on the result whenever the doctype has masked fields for the current user (get_masked_fields()returns[]for Administrator, which is why admins were unaffected).With
pluck=Truethe database layer has already reduced each row to a scalar ([r[0] for r in rows]), soresultis a flat list of values, not a list of rows. Butmask_fields()only knew theas_dict/as_listshapes, so it fell through tomask_list_results(), which doesrow = list(row)on each element:list("P-1156")→['P', '-', '1', '1', '5', '6']→('P', '-', ...)list(42)→TypeError: 'int' object is not iterableFix
Thread a
pluckflag throughmask_fields()and handle it before the dict/tuple paths with a newmask_pluck_results()helper. Becausepluckreturns a single column, the helper masks each scalar only when the plucked field is itself a masked field, and otherwise returns values untouched:name) → unchanged scalar list['XXXXXXXX'])The non-pluck
as_dict/as_listmasking paths are unchanged.Tests
Added
test_get_values_pluck_with_masked_fieldstofrappe/tests/test_db_query.py, covering, for a non-admin user on a doctype with a masked field:TypeError)Verification
The fix was verified behaviorally on a live site (before → after):
name[('e','d','0',...)]['ed0pmvgutd']amount(Int)TypeError[42]secret[('XXXXXXXX','-','1',...)]['XXXXXXXX']as_dict/as_list(non-pluck)🤖 Generated with Claude Code