Commit 894a102
fix: prune PropertyTransformer-controlled subtrees at field-expansion time [DHIS2-21856] (#24519)
* fix: prune PropertyTransformer-controlled subtrees at field-expansion time [DHIS2-21856]
A property annotated @PropertyTransformer (e.g. UserPropertyTransformer, used
on OrganisationUnit.users, UserRole.users, UserGroup.members, and ~12 other
sites) always serializes a fixed shape regardless of what's requested
underneath it -- verified empirically against a live server: fields=users,
fields=users[href] and fields=users[*] all produce byte-identical responses,
one in 6.4s and the other in 138.5s / 583,334 JDBC queries.
Three independent subsystems were each rediscovering (or failing to
discover) this fact on their own:
- FieldFilterService.applyAccess/applySharingDisplayNames, fixed narrowly by
#24514 (DHIS2-21867) via a check inside FieldPathHelper.visitFieldPath.
- DefaultLinkService.generateLink, via AbstractFullReadOnlyController's
hasHref/fieldsContains -- a raw substring check on the unparsed fields
string (fields.contains("*")) that can't tell a top-level wildcard from
one nested four levels deep inside users[*], causing LinkService to
reflectively invoke every IdentifiableObject getter on the schema
(including UserRole.getUsers()) before field-filtering ever runs.
- Jackson's actual serialization, which legitimately needs to enumerate the
collection once -- not addressed here.
Root cause, generalized: FieldPathHelper.apply() generates descendant field
paths under a transformer-controlled property in the first place (confirmed
via FieldFilterParser.parse("users[*]") -> "users", "users.:all", which then
expands into one leaf per property on the target schema, recursively). Every
consumer of the expanded list has to independently re-derive "am I under a
PropertyTransformer" to defensively skip it.
Fix:
- FieldPathHelper.apply() now prunes any path beneath a
PropertyTransformer-annotated property as a final step, before any
consumer sees the list. The property's own bare path always survives
(Jackson only needs it present to include the field at all; its
transformer's DTO has no @jsonfilter, so descendant paths were already a
no-op for serialization -- confirmed by tracing UserPropertyTransformer's
UserDto).
- AbstractFullReadOnlyController.hasHref now asks the real, now-pruned
field-path expansion instead of substring-matching -- correct for every
phrasing (href, id,href, *, :all, :simple, users[href], users[*]) with no
special-casing, and fieldsContains is deleted.
This makes #24514's visitFieldPath check redundant in practice (the paths
it guards against no longer exist to visit) but harmless to keep as
defense-in-depth. Supersedes #24512 (DHIS2-21860), which the team judged too
specific/hard to maintain (per-entity raw-SQL projection plus a
beforeLinkGeneration hook) -- this fixes the shared root for every
@PropertyTransformer site with one change instead.
Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
* test: update skipSharingFieldsExcludeCorrectFieldsTest for PropertyTransformer pruning [DHIS2-21856]
createdBy/lastUpdatedBy use UserPropertyTransformer, so FieldPathHelper.apply()'s
new subtree pruning correctly drops their now-dead createdBy.id/lastUpdatedBy.id
descendant paths generated by the :owner preset expansion, while keeping the
properties' own bare paths. Expected count drops from 58 to 56 accordingly;
added explicit assertions on the surviving/pruned paths so this doesn't regress
to a bare count check again.
Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
* test: collapse PropertyTransformer pruning tests into one parameterized test [DHIS2-21856]
Addresses SonarCloud MAJOR finding on the PR (three near-identical @test
methods differing only in the input fields expression). Mutation-tested:
reverting the pruning logic makes 2 of the 3 parameterized cases fail for
the right reason (the bare "members" case is unaffected either way, since
it has no descendants to prune).
Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
---------
Co-authored-by: Claude Sonnet 5 <noreply@anthropic.com>1 parent 2c241e8 commit 894a102
5 files changed
Lines changed: 280 additions & 11 deletions
File tree
- dhis-2
- dhis-services/dhis-service-field-filtering/src
- main/java/org/hisp/dhis/fieldfiltering
- test/java/org/hisp/dhis/fieldfiltering
- dhis-test-integration/src/test/java/org/hisp/dhis/fieldfiltering
- dhis-test-web-api/src/test/java/org/hisp/dhis/webapi/controller
- dhis-web-api/src/main/java/org/hisp/dhis/webapi/controller
Lines changed: 27 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
91 | 91 | | |
92 | 92 | | |
93 | 93 | | |
| 94 | + | |
| 95 | + | |
94 | 96 | | |
95 | 97 | | |
96 | 98 | | |
| 99 | + | |
| 100 | + | |
| 101 | + | |
| 102 | + | |
| 103 | + | |
| 104 | + | |
| 105 | + | |
| 106 | + | |
| 107 | + | |
| 108 | + | |
| 109 | + | |
| 110 | + | |
| 111 | + | |
| 112 | + | |
| 113 | + | |
| 114 | + | |
| 115 | + | |
| 116 | + | |
| 117 | + | |
| 118 | + | |
| 119 | + | |
| 120 | + | |
| 121 | + | |
| 122 | + | |
| 123 | + | |
97 | 124 | | |
98 | 125 | | |
99 | 126 | | |
| |||
Lines changed: 159 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
| 58 | + | |
| 59 | + | |
| 60 | + | |
| 61 | + | |
| 62 | + | |
| 63 | + | |
| 64 | + | |
| 65 | + | |
| 66 | + | |
| 67 | + | |
| 68 | + | |
| 69 | + | |
| 70 | + | |
| 71 | + | |
| 72 | + | |
| 73 | + | |
| 74 | + | |
| 75 | + | |
| 76 | + | |
| 77 | + | |
| 78 | + | |
| 79 | + | |
| 80 | + | |
| 81 | + | |
| 82 | + | |
| 83 | + | |
| 84 | + | |
| 85 | + | |
| 86 | + | |
| 87 | + | |
| 88 | + | |
| 89 | + | |
| 90 | + | |
| 91 | + | |
| 92 | + | |
| 93 | + | |
| 94 | + | |
| 95 | + | |
| 96 | + | |
| 97 | + | |
| 98 | + | |
| 99 | + | |
| 100 | + | |
| 101 | + | |
| 102 | + | |
| 103 | + | |
| 104 | + | |
| 105 | + | |
| 106 | + | |
| 107 | + | |
| 108 | + | |
| 109 | + | |
| 110 | + | |
| 111 | + | |
| 112 | + | |
| 113 | + | |
| 114 | + | |
| 115 | + | |
| 116 | + | |
| 117 | + | |
| 118 | + | |
| 119 | + | |
| 120 | + | |
| 121 | + | |
| 122 | + | |
| 123 | + | |
| 124 | + | |
| 125 | + | |
| 126 | + | |
| 127 | + | |
| 128 | + | |
| 129 | + | |
| 130 | + | |
| 131 | + | |
| 132 | + | |
| 133 | + | |
| 134 | + | |
| 135 | + | |
| 136 | + | |
| 137 | + | |
| 138 | + | |
| 139 | + | |
| 140 | + | |
| 141 | + | |
| 142 | + | |
| 143 | + | |
| 144 | + | |
| 145 | + | |
| 146 | + | |
| 147 | + | |
| 148 | + | |
| 149 | + | |
| 150 | + | |
| 151 | + | |
| 152 | + | |
| 153 | + | |
| 154 | + | |
| 155 | + | |
| 156 | + | |
| 157 | + | |
| 158 | + | |
| 159 | + | |
Lines changed: 11 additions & 1 deletion
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
120 | 120 | | |
121 | 121 | | |
122 | 122 | | |
123 | | - | |
| 123 | + | |
124 | 124 | | |
125 | 125 | | |
126 | 126 | | |
127 | 127 | | |
128 | 128 | | |
| 129 | + | |
| 130 | + | |
| 131 | + | |
| 132 | + | |
| 133 | + | |
| 134 | + | |
| 135 | + | |
| 136 | + | |
| 137 | + | |
| 138 | + | |
129 | 139 | | |
130 | 140 | | |
131 | 141 | | |
| |||
Lines changed: 61 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
73 | 73 | | |
74 | 74 | | |
75 | 75 | | |
| 76 | + | |
76 | 77 | | |
77 | 78 | | |
78 | 79 | | |
| |||
105 | 106 | | |
106 | 107 | | |
107 | 108 | | |
| 109 | + | |
| 110 | + | |
| 111 | + | |
| 112 | + | |
| 113 | + | |
| 114 | + | |
| 115 | + | |
| 116 | + | |
| 117 | + | |
| 118 | + | |
| 119 | + | |
| 120 | + | |
| 121 | + | |
| 122 | + | |
| 123 | + | |
| 124 | + | |
| 125 | + | |
| 126 | + | |
| 127 | + | |
| 128 | + | |
| 129 | + | |
| 130 | + | |
| 131 | + | |
| 132 | + | |
| 133 | + | |
| 134 | + | |
| 135 | + | |
| 136 | + | |
| 137 | + | |
| 138 | + | |
| 139 | + | |
| 140 | + | |
| 141 | + | |
| 142 | + | |
| 143 | + | |
| 144 | + | |
| 145 | + | |
| 146 | + | |
| 147 | + | |
| 148 | + | |
| 149 | + | |
| 150 | + | |
| 151 | + | |
| 152 | + | |
| 153 | + | |
| 154 | + | |
| 155 | + | |
| 156 | + | |
| 157 | + | |
| 158 | + | |
| 159 | + | |
| 160 | + | |
| 161 | + | |
| 162 | + | |
| 163 | + | |
| 164 | + | |
| 165 | + | |
| 166 | + | |
| 167 | + | |
| 168 | + | |
108 | 169 | | |
109 | 170 | | |
110 | 171 | | |
| |||
Lines changed: 22 additions & 10 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
71 | 71 | | |
72 | 72 | | |
73 | 73 | | |
| 74 | + | |
| 75 | + | |
74 | 76 | | |
75 | 77 | | |
76 | 78 | | |
| |||
127 | 129 | | |
128 | 130 | | |
129 | 131 | | |
| 132 | + | |
| 133 | + | |
130 | 134 | | |
131 | 135 | | |
132 | 136 | | |
| |||
545 | 549 | | |
546 | 550 | | |
547 | 551 | | |
| 552 | + | |
| 553 | + | |
| 554 | + | |
| 555 | + | |
| 556 | + | |
| 557 | + | |
| 558 | + | |
| 559 | + | |
| 560 | + | |
| 561 | + | |
| 562 | + | |
| 563 | + | |
| 564 | + | |
| 565 | + | |
| 566 | + | |
| 567 | + | |
548 | 568 | | |
549 | | - | |
| 569 | + | |
| 570 | + | |
550 | 571 | | |
551 | 572 | | |
552 | 573 | | |
| |||
555 | 576 | | |
556 | 577 | | |
557 | 578 | | |
558 | | - | |
559 | | - | |
560 | | - | |
561 | | - | |
562 | | - | |
563 | | - | |
564 | | - | |
565 | | - | |
566 | | - | |
567 | 579 | | |
568 | 580 | | |
569 | 581 | | |
| |||
0 commit comments