Skip to content

Conversation

cliff688
Copy link
Member

@cliff688 cliff688 commented Aug 29, 2025

Trac ticket number

ticket-36508

Branch description

Matches expectations by reserving the use of None in key transform lookups for JSON null.

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.

@cliff688 cliff688 marked this pull request as draft August 29, 2025 14:27
@cliff688
Copy link
Member Author

buildbot, test on oracle.

@cliff688 cliff688 marked this pull request as ready for review August 30, 2025 06:56
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! This looks good to me 👍

Comment on lines +1434 to +1442
# Interpret '__exact=None' as the SQL 'IS NULL'. For '__iexact=None' on
# KeyTransform, interpret it as '__exact=None' instead of 'IS NULL'
# (#36508). For all other cases, reject the use of None as a query
# value unless the lookup explicitly supports it.
if lookup.rhs is None and not lookup.can_use_none_as_rhs:
if lookup_name not in ("exact", "iexact"):
raise ValueError("Cannot use None as a query value")
if lookup_name == "iexact" and isinstance(lhs, KeyTransform):
return lhs.get_lookup("exact")(lhs, None)
Copy link
Contributor

Choose a reason for hiding this comment

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

Having had another think, it would be preferable if we don't add json specific logic here
Can we not update django.db.models.fields.json.KeyTransformIExact somehow?

Copy link
Member

Choose a reason for hiding this comment

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

I share your sentiment @sarahboyce, this should be implemented at the KeyTransformIExact level and not hardcoded here. The reason why exact and iexact are here today is due to how they must span OUTER JOIN when targeting a reverse relationship, I hope to remove it entirely with #16817.

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.

3 participants