offero / txtelegraf

Twisted Python Client for Telegraf/InfluxDB
Apache License 2.0
1 stars 3 forks source link

float object has no attribute replace #4

Open mattwwarren opened 7 years ago

mattwwarren commented 7 years ago

I have a dict of telegraf tags {u'status': u'success', u'priority': 5.0} that chokes up the conversion to string.

Traceback (most recent call last):
[snip]
  File "/home/mwarren/workspace/venv/lib/python2.7/site-packages/txtelegraf/measurement.py", line 129, in __str__
    return unicode(self).encode('utf-8')
  File "/home/mwarren/workspace/venv/lib/python2.7/site-packages/txtelegraf/measurement.py", line 118, in __unicode__
    tags = format_tags(self.tags)
  File "/home/mwarren/workspace/venv/lib/python2.7/site-packages/txtelegraf/measurement.py", line 69, in format_tags
    return ",".join(("%s=%s" % (format_tag(k), format_tag(v)) for (k, v) in sorted(tags.items())))
  File "/home/mwarren/workspace/venv/lib/python2.7/site-packages/txtelegraf/measurement.py", line 69, in <genexpr>
    return ",".join(("%s=%s" % (format_tag(k), format_tag(v)) for (k, v) in sorted(tags.items())))
  File "/home/mwarren/workspace/venv/lib/python2.7/site-packages/txtelegraf/measurement.py", line 46, in format_tag
    s = s.replace(single_slash, underscore)
AttributeError: 'float' object has no attribute 'replace'
offero commented 7 years ago

Tag values should all be strings (Influx rules).

I'm not sure if we should just try to convert everything to a string for tag values that are not strings. Maybe a developer makes a mistake and puts an object there and calling str() on it just gives a representation of the object. :man_shrugging:

mattwwarren commented 7 years ago

At least for primitive types, should the library convert those?