influxdata / influxdata/influxdb-client-python

Exception from backslash followed by space in field key

未关闭
#660 0 条评论 1 个 reaction 已指派 0 人 在 GitHub 查看

还没有人认领这个 Issue。

bug
主要语言
Python
星标
793
派生
186
平均合并
3 小时 2 分钟
30 天内合并 PR
1

描述

Specifications
  • Client Version: 1.44.0
  • InfluxDB Version: 2.7.6
  • Platform: Linux
Code sample to reproduce problem
#!/usr/bin/env python3
from os import getenv

from influxdb_client import InfluxDBClient
from influxdb_client.client.write.point import Point
from influxdb_client.client.write_api import SYNCHRONOUS


influx_db_client = InfluxDBClient(
    url="http://localhost:8086",
    token=getenv("TEST_TOKEN"),
    org=getenv("TEST_ORG"),
)

write_api = influx_db_client.write_api(write_options=SYNCHRONOUS)

broken_line_protocol_line = Point.from_dict(
        {
            "measurement": "test-measurement-1",
            "tags": {"test-tag-key-X": "test-tag-value-X"},
            "fields": {r"this doesnt \ work": 666},
        }
    ).to_line_protocol()

result = write_api.write(
    getenv("TEST_BUCKET", "missing"),
    getenv("TEST_ORG"),
    broken_line_protocol_line,
)

print(f"result: {result}")
Expected behavior

Either that the data is accepted, or that I get a clear error message that a field keys with a single backslash followed by space is unsupported by Influx. I particularly expect that I get an exception from to_line_protocol rather than that it returns something that is invalid according to Influx and that Influx rejects with "invalid field format".

This problem also arises if giving the point object directly to write rather than going via to_line_protocol, this approach just makes it clear that it can return an invalid line protocol string.

Actual behavior
influxdb_client.rest.ApiException: (400)
Reason: Bad Request
HTTP response headers: HTTPHeaderDict({'Content-Type': 'application/json; charset=utf-8', 'X-Influxdb-Build': 'OSS', 'X-Influxdb-Version': 'v2.7.6', 'X-Platform-Error-Code': 'invalid', 'Date': 'Wed, 26 Jun 2024 13:28:23 GMT', 'Content-Length': '152'})
HTTP response body: {"code":"invalid","message":"unable to parse 'test-measurement-1,test-tag-key-X=test-tag-value-X this\\ doesnt\\ \\\\ work=666i': invalid field format"}

If I remove either the slash followed by space or the space, it works.

Additional info

AFAIK Influx doesn't support field keys that have a single backslash followed by a space? I intend to replace backslash-space with double-backslash-space on my end for backwards compatibility either way, but this tripped up four people at work when they upgraded and something that used to work (albeit by subtly turning a single into a double backslash) instead blew up with an exception.

influxdb-client 1.19.0 doesn't report an error and the values end up in the database, but it ends up with double backslashes for fields and tags.

贡献指南

这个仓库没有索引到贡献指南

从这里开始

  1. 先读完整个 Issue,再读项目的贡献指南。
  2. 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
  3. Fork 仓库,在一个分支上完成修改。
  4. 提交 Pull Request,并在描述里引用这个 Issue 编号。

调研方向

从 Point.from_dict 和 to_line_protocol 开始,然后跟踪字段键在 write 将 line protocol 发送到 InfluxDB 之前是如何进行转义的。复现 issue 中的反斜杠-空格情况,并确保序列化要么生成有效的 line protocol,要么在发送请求之前引发明确的错误。

由索引模型根据 Issue 内容生成。

评估

技术栈
python
领域
api
Issue 类型
缺陷
难度
3/5
预计耗时
1-2 天
活跃度
停滞
描述清晰度
基本清楚
新手友好度
48/100

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。