Opened 32 hours ago

Last modified 29 hours ago

#36139 assigned New feature

Allow expressing JSONObject keys dynamically, as well as explicit pair-values

Reported by: john-parton Owned by: john-parton
Component: Database layer (models, ORM) Version: dev
Severity: Normal Keywords:
Cc: Triage Stage: Unreviewed
Has patch: yes Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

Description

In working towards supporting ABSENT ON NULL for JSONArray, I did some digging on what it would take to implement it for JSONObject as well, and essentially, because the init signature consumes all the kwargs, there's not really a good way to configure its behavior without conflicting with a key definition.

If you could specify the items of a JSONObject positionally, then you get the aforementioned benefit of being able to have kwargs as well without conflicting, but you also get the added benefit of being able to construct objects with non-static keys.

As an example esoteric usage, if you're trying to get the database to omit valid objects for the Elasticsearch DSL, you would almost certainly need to be able to build objects with non-static keys.

For example https://www.elastic.co/guide/en/elasticsearch/reference/current/query-dsl-term-query.html

The key "user.id" refers to a field in elastic.

See some discussion here: https://github.com/django/django/pull/19097#issuecomment-2611270246

I'll throw together a patch.

Change History (3)

comment:1 by john-parton, 31 hours ago

Pull request/patch here: https://github.com/django/django/pull/19101

Not too bad for the actual code change, just a few lines. Several tests added and expanded the Usage section of the documentation sufficiently to cover the various use cases.

comment:2 by john-parton, 31 hours ago

Has patch: set

comment:3 by Antoliny, 29 hours ago

Owner: set to john-parton
Status: newassigned
Note: See TracTickets for help on using tickets.
Back to Top