Visitar URL original
[Django 6.1] JSONField key iexact=None lookup returns wrong results on SQL Server · Issue #574 · microsoft/mssql-django · GitHub
Skip to content

[Django 6.1] JSONField key iexact=None lookup returns wrong results on SQL Server #574

Open

Description

Problem
A case-insensitive JSON key lookup against None returns the wrong result set on SQL Server. The failure is silent (no error, wrong rows).

Repro

# value is a JSONField; object has {"j": None} stored
NullableJSONModel.objects.filter(value__j__iexact=None)

Expected: rows whose JSON key j is JSON null. Actual: incorrect result set on SQL Server, which has no native JSON null handling for this path.

Scope
Not a 6.1 regression. Sibling to the existing JSONField lookup limitations; the backend JSON handling is not version gated, so this affects all supported Django versions on SQL Server. Django 6.1 added model_fields.test_jsonfield.TestQuerying.test_key_iexact_none, which surfaced it. The test is skipped in testapp/settings.py.

Possible fix
Handle key__iexact=None in the JSON lookup compilation, consistent with the other JSONField null lookups. See the JSONField wiki page.

Activity

  1. added
    bugSomething isn't working
    area: orm-queryQuery compilation, GROUP BY, CTE, window funcs, slicing/FETCH, ORM behaviour
    area: django-compatDjango version compat, feature requests, test infra, ecosystem deps
    on Aug 7, 2026
  2. changed the title [-]JSONField key iexact=None lookup returns wrong results on SQL Server[/-] [+][Django 6.1] JSONField key iexact=None lookup returns wrong results on SQL Server[/+] on Aug 7, 2026
  3. vivekjm commented on Aug 11, 2026

    @vivekjm

    I’m working on a focused fix for this. I’ll trace the existing JSON null lookup compilation, add regression coverage for key__iexact=None, and keep the change scoped to the backend SQL generation.

  4. bewithgaurav commented on Aug 11, 2026

    @bewithgaurav
    CollaboratorAuthor

    Vivek JM (@vivekjm) sure please go ahead - looking forward to the PR :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    area: django-compatDjango version compat, feature requests, test infra, ecosystem depsarea: orm-queryQuery compilation, GROUP BY, CTE, window funcs, slicing/FETCH, ORM behaviourbugSomething isn't workinggood first issueGood for newcomers

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions