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

未關閉
#1,716 0 則留言 0 個 reaction 已指派 0 人 在 GitHub 檢視

維護者通常 5 天內回覆

還沒有人認領這個 Issue。

評估

難度
3/5
預估耗時
1-2 天
新手友好度
78/100
Issue 類型
缺陷
描述清晰度
描述清楚
活躍度
活躍
技術堆疊
mysql, postgresql, python

研究方向

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.

由索引模型根據 Issue 內容生成。

描述

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.
主要語言
Python
星號
198
分支
107
平均合併
4 天 7 小時
30 天內合併 PR
12

環境準備

  • 提供 Dockerfile 或 Docker Compose 檔案
  • 沒有 Pull Request 範本
  • 閱讀貢獻指南

從這裡開始

  1. 先讀完整個 Issue,再讀專案的貢獻指南。
  2. 在 Issue 下留言說明你要接手 —— 這能避免兩個人做同樣的事。
  3. Fork 儲存庫,在一個分支上完成修改。
  4. 送出 Pull Request,並在描述裡引用這個 Issue 編號。

datajoint/datajoint-python 的其他 Issue

查看 datajoint/datajoint-python 的全部 Issue

相似的 Issue

更多 Python Issue

把新 issue 寄到你的電子郵件信箱

精選適合新手參與的 GitHub issue 摘要。