﻿id	summary	reporter	owner	description	type	status	component	version	severity	resolution	keywords	cc	stage	has_patch	needs_docs	needs_tests	needs_better_patch	easy	ui_ux
37297	Programming error when the first JSONField path segment is an integer overflowing int4's range on PostgreSQL	Clifford Gama	Clifford Gama	"JSONField key lookup raises an unhandled ProgrammingError (""operator does not exist: jsonb -> bigint"") instead of behaving like any other out-of-range/non-matching lookup, when a purely-numeric key segment decimal-parses to a value outside PostgreSQL's `int4` range.

I had a JSONField whose keys are generated using `uuid.uuid4().hex[:12]`. When a key was all-digit, this ran into #29504, leading to flaky tests when I did something like `.filter(**{key: ""some value""})`. That's because Django [https://github.com/django/django/blob/0b40210e4808937a7c0922e8b7502bff4752faa3/django/db/models/fields/json.py#L503 interprets an integer key segment as an array index] rather than a text path -- but only when it's the lookup's sole segment. In this case, though, instead of getting no match, I got a `ProgrammingError`: the number overflowed int, and `->` isn't overloaded for bigint.

{{{
operator does not exist: jsonb -> bigint
HINT:  No operator matches the given name and argument types. You
       might need to add explicit type casts.
}}}

Since Django is guessing if an all-number string is an array index, I suggest that we treat numbers outside of the allowed range as strings.

See attached PR for a regression test."	Bug	assigned	Database layer (models, ORM)	dev	Normal		JSONField, PostgreSQL, KeyTransform, jsonb		Unreviewed	1	0	0	0	0	0
