Opened 46 minutes ago
#37349 new Cleanup/optimization
Add note about object key order in JSONField docs
| Reported by: | Lincoln | Owned by: | |
|---|---|---|---|
| Component: | Documentation | Version: | dev |
| Severity: | Normal | Keywords: | |
| Cc: | Lincoln | Triage Stage: | Unreviewed |
| Has patch: | no | Needs documentation: | no |
| Needs tests: | no | Patch needs improvement: | no |
| Easy pickings: | no | UI/UX: | no |
Description
Using JSONField with PostgreSQL, storing a dict in the field and then later retrieving it, will not preserve the key order,
because PostgreSQL jsonb type "does not preserve the order of object keys" (https://www.postgresql.org/docs/current/datatype-json.html).
This behavior can be surprising, because python dict does preserve key order, and storing/retrieving dicts with json.dumps/json.loads will preserve key order.
So, I am proposing to add a note to the JSONField docs explaining that key order may not be preserved. This could go in either the current "PostgreSQL users" note, or a new note. This probably depends on if the other DB backends preserve key order. I haven't checked if any of the others do.