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

Escape tag values that ends with backslash #537

Merged
merged 4 commits into from
Dec 11, 2017

Conversation

vaniakov
Copy link
Contributor

If we try to write tag value that ends with backslash we get an InfluxDB error:

$ ipython3
Python 3.5.2 (default, Nov 17 2016, 17:05:23)
Type 'copyright', 'credits' or 'license' for more information
IPython 6.2.0 -- An enhanced Interactive Python. Type '?' for help.

In [1]: from influxdb import InfluxDBClient
   ...: client = InfluxDBClient()
   ...: client.create_database('statistics')
   ...: client.switch_database('statistics')
   ...:

In [2]: data = [
   ...:     {
   ...:      'measurement': 'disk_usage',
   ...:      'tags':{
   ...:         'device': 'C:\\'
   ...:         },
   ...:         'fields': {
   ...:             'total_bytes': 9846712221,
   ...:             'free_bytes': 971245124
   ...:         }
   ...:     }
   ...: ]

In [3]: client.write_points(data)
---------------------------------------------------------------------------
InfluxDBClientError                       Traceback (most recent call last)
<ipython-input-3-66de51fff414> in <module>()
----> 1 client.write_points(data)

/usr/local/lib/python3.5/dist-packages/influxdb/client.py in write_points(self, points, time_precision, database, retention_policy, tags, batch_size, protocol)
    454                                       database=database,
    455                                       retention_policy=retention_policy,
--> 456                                       tags=tags, protocol=protocol)
    457
    458     def _batches(self, iterable, size):

/usr/local/lib/python3.5/dist-packages/influxdb/client.py in _write_points(self, points, time_precision, database, retention_policy, tags, protocol)
    504                 params=params,
    505                 expected_response_code=204,
--> 506                 protocol=protocol
    507             )
    508

/usr/local/lib/python3.5/dist-packages/influxdb/client.py in write(self, data, params, expected_response_code, protocol)
    300             data=data,
    301             expected_response_code=expected_response_code,
--> 302             headers=headers
    303         )
    304         return True

/usr/local/lib/python3.5/dist-packages/influxdb/client.py in request(self, url, method, params, data, expected_response_code, headers)
    261             return response
    262         else:
--> 263             raise InfluxDBClientError(response.content, response.status_code)
    264
    265     def write(self, data, params=None, expected_response_code=204,

InfluxDBClientError: 400: {"error":"unable to parse 'disk_usage,device=C:\\\\ free_bytes=971245124i,total_bytes=9846712221i': invalid tag format"}

This is workaround for InfluxDB issue, the same reproduces in influx cli:

$ influx
Visit https://enterprise.influxdata.com to register for updates, InfluxDB server management, and monitoring.
Connected to http://localhost:8086 version 0.10.0
InfluxDB shell 0.10.0
> use statistics
Using database statistics
> insert disk_usage,device=C:\\\\ free_bytes=971245124i,total_bytes=9846712221i
ERR: {"error":"unable to parse 'disk_usage,device=C:\\\\\\\\ free_bytes=971245124i,total_bytes=9846712221i': invalid tag format"}

> insert disk_usage,device=C:\\  free_bytes=971245124i,total_bytes=9846712221i
> select * from disk_usage
name: disk_usage
----------------
time                    device  free_bytes      total_bytes
1510913194937625701     C:\     971245124       9846712221

@xginn8
Copy link
Collaborator

xginn8 commented Nov 18, 2017

Thanks for contributing! Would you mind adding a test case for this PR?

@vaniakov
Copy link
Contributor Author

@xginn8 sure.

@@ -39,9 +40,10 @@ def test_make_lines(self):
]
}

print(line_protocol.make_lines(data))
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remove the print please

@vaniakov
Copy link
Contributor Author

@xginn8, @aviau could you please verify changes?

@xginn8 xginn8 merged commit 6b5db78 into influxdata:master Dec 11, 2017
@vaniakov
Copy link
Contributor Author

Thank you!

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

Successfully merging this pull request may close these issues.

3 participants