Skip to content

PostgreSQL: a string restriction value with a backslash does not match the stored value #1716

Open

Description

@dimitri-yatsenko

Summary

On PostgreSQL, a string value in a dict restriction that contains a backslash does not match the row that stores that value. This holds for attributes and for JSON paths compared with a string.

prep_value in condition.py doubles every backslash in a string value on PostgreSQL before quoting it, as earlier releases did. PostgreSQL has standard_conforming_strings on by default, so in a plain '...' literal a backslash is an ordinary character. The doubled literal then names a different string.

Item.insert1(dict(item_id=5, name="back\\slash"))   # stored: back\slash
Item & {"name": "back\\slash"}                      # MySQL: 1 row; PostgreSQL: 0 rows
Item & {"data.label": "back\\slash"}                # same, for a JSON path

tests/integration/test_restriction_values.py::test_string_with_backslash asserts the match on MySQL only.

2.3.x keeps the current behavior, so that a patch release does not change which rows a restriction selects.

Proposal for 2.4

  • Stop doubling backslashes in plain string values on PostgreSQL. Render them the way list values already are: as an E'...' literal with escaped backslashes, which reads the same whether standard_conforming_strings is on or off.
  • Extend test_string_with_backslash to PostgreSQL.
  • Note the change in the 2.4 release notes: a string restriction with a backslash now matches the stored value on PostgreSQL.

Activity

  1. added this to the v2.4 milestone on Nov 20, 2026
  2. added
    bugIndicates an unexpected problem or unintended behavior
    on Nov 20, 2026
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

    bugIndicates an unexpected problem or unintended behavior

    Type

    No type

    Projects

    No projects

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions