Envelopes + responses¶
The WebMessageResponse envelope and its inner shapes (ObjectReport, ImportReport, ImportCount, Conflict, ErrorReport, Stats, TypeReport). Every DHIS2 write endpoint returns one of these shapes.
envelopes
¶
DHIS2 WebMessageResponse + ImportReport envelopes (shim over generated/v42/oas).
The raw shapes come from /api/openapi.json#/components/schemas/{WebMessage,
ObjectReport, ImportReport, TypeReport, Stats, ErrorReport, ImportConflict,
ImportCount} — see dhis2w_client.generated.v42.oas. This module re-exports
those classes under their domain names and adds the helper methods
(created_uid, task_ref, object_report, import_count, import_report,
conflicts, conflict_rows, rejected_indexes) on WebMessageResponse
that callers rely on.
Every POST/PUT/DELETE/PATCH through /api/* returns a WebMessageResponse.
Its response field carries an endpoint-specific payload; the helper methods
project it into the right typed shape (ObjectReport for CRUD, ImportReport
for /api/metadata, ImportCount for /api/dataValueSets, etc.).
DHIS2 uses TWO different error shapes depending on the endpoint:
/api/dataValueSets+/api/trackerreturnresponse.conflicts[]— a flat list ofImportConflictrows.conflicts()returns these verbatim./api/metadatareturnsresponse.typeReports[*].objectReports[*].errorReports[*]— a three-level tree tagging each error with the owning resource type + UID.conflicts()misses these entirely (they're not underresponse.conflicts).
conflict_rows() normalises both shapes into a uniform ConflictRow list so
CLI renderers can show a single Rich table regardless of the endpoint.
Classes¶
ErrorReport
¶
Bases: BaseModel
OpenAPI schema ErrorReport.
Source code in packages/dhis2w-client/src/dhis2w_client/generated/v42/oas/error_report.py
ImportCount
¶
Bases: BaseModel
OpenAPI schema ImportCount.
Source code in packages/dhis2w-client/src/dhis2w_client/generated/v42/oas/import_count.py
ImportReport
¶
Bases: BaseModel
OpenAPI schema ImportReport.
Source code in packages/dhis2w-client/src/dhis2w_client/generated/v42/oas/import_report.py
ObjectReport
¶
Bases: BaseModel
OpenAPI schema ObjectReport.
Source code in packages/dhis2w-client/src/dhis2w_client/generated/v42/oas/object_report.py
Stats
¶
Bases: BaseModel
OpenAPI schema Stats.
Source code in packages/dhis2w-client/src/dhis2w_client/generated/v42/oas/stats.py
TypeReport
¶
Bases: BaseModel
OpenAPI schema TypeReport.
Source code in packages/dhis2w-client/src/dhis2w_client/generated/v42/oas/type_report.py
ConflictRow
¶
Bases: BaseModel
Normalised conflict row — uniform across /api/metadata and /api/dataValueSets.
response.conflicts[] (data-value / tracker) and
response.typeReports[*].objectReports[*].errorReports[*] (metadata)
both flatten to this shape via WebMessageResponse.conflict_rows(),
so CLI renderers can print one Rich table regardless of the source.
Source code in packages/dhis2w-client/src/dhis2w_client/envelopes.py
Attributes¶
resource = None
class-attribute
instance-attribute
¶
Resource type — "DataElement" / "OrganisationUnit" etc., stripped
from DHIS2's fully-qualified klass strings.
uid = None
class-attribute
instance-attribute
¶
UID of the owning object (if DHIS2 surfaced one).
property = None
class-attribute
instance-attribute
¶
Property that tripped the error — "name", "categoryCombo", etc.
value = None
class-attribute
instance-attribute
¶
Offending value, or rich context DHIS2 tucked on value / objects.
error_code = None
class-attribute
instance-attribute
¶
DHIS2 error code — E4003, E5003, etc. Stable across versions.
message = None
class-attribute
instance-attribute
¶
Human-readable error message DHIS2 rendered (includes args substituted).
indexes = None
class-attribute
instance-attribute
¶
Payload-array indexes the conflict applies to (data-value / tracker imports).
WebMessageResponse
¶
Bases: WebMessage
DHIS2 write-response envelope with typed helper accessors.
Inherits every wire field from WebMessage (httpStatus, httpStatusCode,
status, code, message, devMessage, errorCode, response) and adds
helper methods that project the endpoint-specific response dict into the
right typed shape.
Source code in packages/dhis2w-client/src/dhis2w_client/envelopes.py
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 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 | |
Attributes¶
created_uid
property
¶
Pull response.uid when the inner envelope is an ObjectReport.
DHIS2's ObjectReport names the created identifier uid (not id) —
see BUGS.md #4f. This property hides the defensive lookup.
Functions¶
task_ref()
¶
Return (job_type, task_uid) when DHIS2 returned a job-kickoff envelope.
Every /api/*/async or /api/resourceTables/analytics-style endpoint
returns a JobConfigurationWebMessageResponse with response.jobType
and response.id. Callers that want to watch the job to completion
feed this tuple to maintenance.service.watch_task.
Source code in packages/dhis2w-client/src/dhis2w_client/envelopes.py
object_report()
¶
Validate response as an ObjectReport — useful after single-object CRUD.
import_count()
¶
Validate response (or response.importCount) as an ImportCount.
DHIS2 uses two shapes for the counts: some endpoints inline them at
response.imported / response.updated / ...; others nest them under
response.importCount = {...}. Both reach the same parsed model.
Source code in packages/dhis2w-client/src/dhis2w_client/envelopes.py
import_report()
¶
Validate response as an ImportReport — useful after metadata bulk imports.
conflicts()
¶
Pull response.conflicts[] — per-row rejections from a data-value or tracker import.
Does NOT surface metadata-import errors (those live under
response.typeReports[*].objectReports[*].errorReports[*] instead).
Use conflict_rows() for a uniform view across both shapes.
Source code in packages/dhis2w-client/src/dhis2w_client/envelopes.py
conflict_rows()
¶
Return every error / conflict on the envelope, normalised to ConflictRow.
Walks both DHIS2 shapes and merges:
- Flat
response.conflicts[](data-value / tracker imports) — each entry becomes one row withproperty+value+error_code+indexespopulated. - Nested
response.typeReports[*].objectReports[*].errorReports[*](metadata imports) — eachErrorReportbecomes one row withresource(from the owningTypeReport.klass),uid(from theObjectReport),property(errorProperty),error_code, andmessageall set.
Empty list on a clean response. The flat list is stable across the two input shapes so CLI renderers can print one Rich table.
Source code in packages/dhis2w-client/src/dhis2w_client/envelopes.py
rejected_indexes()
¶
Pull response.rejectedIndexes[] — payload-array indexes DHIS2 refused to import.