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 摘要。