Hacktoberfest 2026: as issues que os mantenedores marcaram para outubro, abertas e boas para iniciantes. Ver issues do Hacktoberfest

firestore: field path with a quoted name ending in a backslash is misparsed

Aberta Para iniciantes
#18,771 0 comentários 0 reações 0 responsáveis Ver no GitHub

Mantenedores costumam responder em até 1 dia

@auraseb já está trabalhando nisso.

Desde 19/10/2026.

  • #18772 de @auraseb — aberto

Avaliação

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

Direção de pesquisa

Comece por google/cloud/firestore_v1/field_path.py e inspecione o padrão do token QUOTED usado por FieldPath.from_api_repr(); reproduza a falha com o exemplo de FieldPath fornecido. Confira os testes do parser de caminhos de campo e adicione cobertura para um segmento entre aspas que termina com uma barra invertida, seguido por outro segmento. A tarefa estará concluída quando a representação da API for analisada de volta para as partes originais e a atualização atingir o campo aninhado descrito na issue.

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

Descrição

Package: google-cloud-firestore (google/cloud/firestore_v1/field_path.py), current main.

What happens

FieldPath.to_api_repr() escapes a trailing backslash correctly, but the parser cannot read the result back when another quoted segment follows it. FieldPath.from_api_repr() raises ValueError, and FieldPath.from_string() catches that error and falls back to a plain split on ., so it silently returns parts that still contain the backticks and escape characters.

Because update() and set(..., merge=[...]) go through FieldPath.from_string() / parse_field_path(), the write goes to the wrong field.

Minimal repro
from google.cloud.firestore_v1.field_path import FieldPath
from google.cloud.firestore_v1 import _helpers

s = FieldPath("dir\\", "file name").to_api_repr()
print(s)                                  # `dir\\`.`file name`
print(FieldPath.from_string(s).parts)     # ('`dir\\\\`', '`file name`')
FieldPath.from_api_repr(s)                # ValueError: Invalid path

pbs = _helpers.pbs_for_update("projects/p/databases/d/documents/c/doc", {s: 1}, None)
print(list(pbs[0].update.fields))         # ['`dir\\\\`']
What should happen

The string produced by to_api_repr() should parse back to the same parts, ('dir\\', 'file name'), and the update should target dir\ > file name.

Root cause

The QUOTED token pattern is r"`(?:\\`|[^`])*?`". In `dir\\`.`file name` the lazy match takes the second backslash together with the closing backtick as an escaped backtick (\`), so the token runs on to the next backtick and swallows `.`. What remains (file name`) does not tokenize, so parsing fails. The pattern needs to treat a backslash as an escape for the next character, not only for a backtick, and should not let a bare backslash match on its own.

Linguagem predominante
Python
Estrelas
5.4k
Forks
1.8k
Merge médio
2d 1h
PRs com merge (30d)
191

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 googleapis/google-cloud-python

Todas as issues de googleapis/google-cloud-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.