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

Offen
#1,716 0 Kommentare 0 Reaktionen 0 zugewiesene Personen Auf GitHub ansehen

Maintainer antworten meist innerhalb von 5 Tagen

Dieses Issue hat noch niemand übernommen.

Bewertung

Schwierigkeit
3/5
Geschätzter Aufwand
1-2 Tage
Anfängerfreundlichkeit
78/100
Issue-Typ
Bug
Klarheit
Klar beschrieben
Aktivitätsstatus
Aktiv
Tech-Stack
mysql, postgresql, python

Rechercherichtung

Start with prep_value in condition.py and read tests/integration/test_restriction_values.py::test_string_with_backslash to understand how string values and JSON path restrictions are tested. Extend the test to PostgreSQL, then check the 2.4 release notes. Done when PostgreSQL matches stored backslash values for attributes and JSON paths, the existing MySQL check still passes, and the change is documented.

Vom Indexierungsmodell aus dem Issue-Text verfasst.

Beschreibung

bug

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.
Vorherrschende Sprache
Python
Sterne
198
Forks
107
Ø Merge
4 T. 7 Std.
Gemergte PRs (30 T.)
12

Entwicklungsumgebung

Erste Schritte

  1. Lesen Sie das ganze Issue und danach den Beitragsleitfaden des Projekts.
  2. Schreiben Sie ins Issue, dass Sie es übernehmen — das erspart doppelte Arbeit.
  3. Forken Sie das Repository und arbeiten Sie in einem Branch.
  4. Öffnen Sie einen Pull Request, der die Issue-Nummer nennt.

Mehr aus datajoint/datajoint-python

Alle Issues in datajoint/datajoint-python

Ähnliche Issues

Weitere Issues zu Python

Neue Issues direkt in Ihr Postfach

Eine kurze Übersicht über anfängerfreundliche GitHub-Issues.