influxdata / influxdb-client-python

InfluxDB 2.0 python client
https://influxdb-client.readthedocs.io/en/stable/
MIT License
724 stars 187 forks source link

A bug in the official example #553

Closed occoder closed 3 months ago

occoder commented 1 year ago

Specifications

Code sample to reproduce problem

from datetime import datetime

from influxdb_client import WritePrecision, InfluxDBClient, Point
from influxdb_client.client.write_api import SYNCHRONOUS

with InfluxDBClient(url="http://localhost:8086", token="my-token", org="my-org", debug=False) as client:
    query_api = client.query_api()

    p = Point("my_measurement").tag("location", "Prague").field("temperature", 25.3).time(datetime.utcnow(),
                                                                                          WritePrecision.MS)
    write_api = client.write_api(write_options=SYNCHRONOUS)

    # write using point structure
    write_api.write(bucket="my-bucket", record=p)

    line_protocol = p.to_line_protocol()
    print(line_protocol)

    # write using line protocol string
    write_api.write(bucket="my-bucket", record=line_protocol)

The code snippet is exactly taken from the offical example.

Expected behavior

Both Point and Line protocol commands could write through.

Actual behavior

Only the Point style write succeeded. The Line protocol gave following error prompt

influxdb_client.rest.ApiException: (422)
Reason: Unprocessable Entity
HTTP response headers: HTTPHeaderDict({'Content-Type': 'application/json; charset=utf-8', 'X-Influxdb-Build': 'OSS', 'X-Influxdb-Version': 'v2.6.1', 'X-Platform-Error-Code': 'unprocessable entity', 'Date': 'Thu, 12 Jan 2023 06:55:39 GMT', 'Content-Length': '135'})HTTP response body: {"code":"unprocessable entity","message":"failure writing points to database: partial write: points beyond retention policy dropped=1"}

Additional info

No response

srebhan commented 3 months ago

@occoder the error tells you that the server thinks that the point you are writing is before the configured retention policy and would therefore be directly deleted by the database. There is nothing wrong with the example, the issue is likely the configured retention policy and/or a wrong clock on either the server or client side.