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

Aberta
#1,716 0 comentários 0 reações 0 responsáveis Ver no GitHub

Mantenedores costumam responder em até 5 dias

Ninguém assumiu esta issue ainda.

Avaliação

Dificuldade
3/5
Tempo estimado
1-2 dias
Facilidade para iniciantes
78/100
Tipo de issue
Bug
Clareza
Claramente especificada
Status de atividade
Ativa
Stack de tecnologia
mysql, postgresql, python
Domínio
backend, database, testing

Direção de pesquisa

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.

Escrita pelo modelo de indexação a partir do texto da issue.

Descrição

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.
Linguagem predominante
Python
Estrelas
198
Forks
107
Merge médio
4d 7h
PRs com merge (30d)
12

Preparar o ambiente

Primeiros passos

  1. Leia a issue inteira e depois o guia de contribuição do projeto.
  2. Comente na issue dizendo que vai assumir — evita que duas pessoas façam o mesmo trabalho.
  3. Faça um fork do repositório e trabalhe em uma branch.
  4. Abra um pull request que referencie o número da issue.

Mais de datajoint/datajoint-python

Todas as issues de datajoint/datajoint-python

Issues semelhantes

Mais issues de Python

Receba novas issues na sua caixa de entrada

Um resumo curto de issues do GitHub para quem está começando.