Skip to content
This repository was archived by the owner on Oct 29, 2024. It is now read-only.

Measurement names are not escaped in _dataframe_client.py; spaces in names improperly handled #520

Closed
mkarlesky opened this issue Oct 23, 2017 · 7 comments

Comments

@mkarlesky
Copy link

We hacked a patch by calling _escape_tag(measurement) at the end of _convert_dataframe_to_lines().

@xginn8
Copy link
Collaborator

xginn8 commented Nov 25, 2017

@mkarlesky can you provide an example where this fails? I'm having trouble reproducing it.

@garrettkatz
Copy link

Here's an example that fails in my environment. Using the influx cli:

> create database "test"

In a python shell, with X.X.X.X replaced by the host IP:

>>> import pandas as pd
>>> from influxdb import DataFrameClient
>>> c = DataFrameClient(host="X.X.X.X", database="test")
>>> d = pd.DataFrame(data=[[0],[1]], columns=["A"], index=pd.date_range(start="1-1-2018",end="1-2-2018",freq="1D"))
>>> c.write_points(d, measurement="Test Measurement", field_columns=["A"], protocol="line")
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/home/cruncher/.local/lib/python2.7/site-packages/influxdb/_dataframe_client.py", line 131, in write_points
    protocol=protocol)
  File "/home/cruncher/.local/lib/python2.7/site-packages/influxdb/client.py", line 456, in write_points
    tags=tags, protocol=protocol)
  File "/home/cruncher/.local/lib/python2.7/site-packages/influxdb/client.py", line 506, in _write_points
    protocol=protocol
  File "/home/cruncher/.local/lib/python2.7/site-packages/influxdb/client.py", line 302, in write
    headers=headers
  File "/home/cruncher/.local/lib/python2.7/site-packages/influxdb/client.py", line 263, in request
    raise InfluxDBClientError(response.content, response.status_code)
influxdb.exceptions.InfluxDBClientError: 400: {"error":"unable to parse 'Test Measurement A=0i 1514764800000000000': invalid field format\nunable to parse 'Test Measurement A=1i 1514851200000000000': invalid field format"}
>>> c.write_points(d, measurement="Test_Measurement", field_columns=["A"], protocol="line")
True

And more specifically, the patch we came up with was to change the line at the end of _convert_dataframe_to_lines(...) in _dataframe_client.py from

points = (measurement + tags + ' ' + fields + ' ' + time).tolist()

to

points = (_escape_tag(measurement) + tags + ' ' + fields + ' ' + time).tolist()

@xginn8
Copy link
Collaborator

xginn8 commented Nov 30, 2017

excellent, thanks for the repro! I'll take a look at this.

@xginn8
Copy link
Collaborator

xginn8 commented Nov 30, 2017

note this does work with protocol=json, as an immediate workaround

@garrettkatz
Copy link

garrettkatz commented Nov 30, 2017 via email

tzonghao added a commit to tzonghao/influxdb-python that referenced this issue Dec 6, 2017
xginn8 pushed a commit that referenced this issue Dec 12, 2017
* Fixed: DataFrameClient should escape measurement names

Issue #520

* Fix pep257 error
@xginn8
Copy link
Collaborator

xginn8 commented Dec 12, 2017

This issue was fixed in #542

@xginn8 xginn8 closed this as completed Dec 12, 2017
@garrettkatz
Copy link

garrettkatz commented Dec 12, 2017 via email

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants