Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixed #35778 -- Used JSON_OBJECT database function on PostgreSQL 16+ with server-side bindings. #18622

Conversation

john-parton
Copy link
Contributor

@john-parton john-parton commented Sep 26, 2024

Fixed #35778 -- Use native JSON_OBJECT on postgres 16+ with server-side binding.

Trac ticket number

https://code.djangoproject.com/ticket/35778#ticket

Branch description

In a prior version of Django, there was an attempt to use the JSON_OBJECT function on postgres 16+ with server side bindings, but it didn't work because keys must be cast to text. This change makes it so that keys are always cast to text when using postgres. It also wraps the keys in parenthesis on all backends to remove a parsing error while using :: to cast within the context of the json_object function which uses : to separate keys.

Checklist

  • This PR targets the main branch.
  • The commit message is written in past tense, mentions the ticket number, and ends with a period.
  • I have checked the "Has patch" ticket flag in the Trac system.
  • I have added or updated relevant tests.
  • I have added or updated relevant docs, including release notes if applicable.
  • I have attached screenshots in both light and dark modes for any UI changes.

@john-parton john-parton marked this pull request as ready for review October 1, 2024 16:20
@john-parton
Copy link
Contributor Author

john-parton commented Oct 1, 2024

I went ahead and marked this as ready for review, just so it has higher visibility.

I believe my changes do exactly what they are supposed to do, but I'm open to additional discussion/brainstorming.

A little meta discussion There's not a particular reason that we need to prefer using JSON_OBJECT over JSONB_BUILD_OBJECT at this time. We have to support both because of the supported Postgres versions. I presume the reason this was even pursued in the first place is so that when Postgres 16 support is dropped, this function could be simplified. However, that's scheduled for 2027, so we've got a tiny bit of time.

@john-parton john-parton force-pushed the feature/35778-native-json-on-postgres-with-ssb branch from 277a647 to 5075141 Compare October 16, 2024 19:44
@john-parton
Copy link
Contributor Author

Rebased. I ran the tests locally and they all succeeded, but that's just my specific config. Pushed to run through test suite again.

@nessita
Copy link
Contributor

nessita commented Oct 17, 2024

@charettes @felixxm Would any/both of you be keen to do an initial review?

Copy link
Member

@charettes charettes left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@nessita the patch LGTM, not entirely convinced a release note is warranted given how recent the function is that it's most likely not used in an expression index at this point.

django/db/models/functions/comparison.py Outdated Show resolved Hide resolved
@sarahboyce
Copy link
Contributor

buildbot, test on oracle.

@sarahboyce sarahboyce changed the title Fixed #35778 -- Use native JSON_OBJECT on postgres 16+ with server-side binding. Fixed #35778 -- Used JSON_OBJECT database function on PostgreSQL 16+ with server-side bindings. Nov 5, 2024
Copy link
Contributor

@sarahboyce sarahboyce left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you @john-parton 👍

django/db/models/functions/comparison.py Show resolved Hide resolved
@sarahboyce sarahboyce force-pushed the feature/35778-native-json-on-postgres-with-ssb branch 2 times, most recently from 737c75a to 65156c6 Compare November 6, 2024 10:24
@sarahboyce sarahboyce force-pushed the feature/35778-native-json-on-postgres-with-ssb branch from 65156c6 to fd26bfa Compare November 6, 2024 10:25
@sarahboyce
Copy link
Contributor

buildbot, test on oracle.

@sarahboyce sarahboyce merged commit 78c9a27 into django:main Nov 6, 2024
44 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants