google / starlark-go

Starlark in Go: the Starlark configuration language, implemented in Go
BSD 3-Clause "New" or "Revised" License
2.26k stars 204 forks source link

Bug: Can't move key-value pairs from fields to tags #528

Closed wpesotsky closed 4 months ago

wpesotsky commented 4 months ago

There seems to be a bug where it is not possible to remove a key-value pair from the fields dict without deleting the same entry from tags. I need move all non-numeric values to tags. I'm doing this by copying the entry to tags and deleting the entry in fields but it also disappears in the tags dict.

Am I making a mistake or is this indeed a bug?

Telegraf version 1.29.5. Here is my Starlark code:


def apply(metric):

  for k, v in metric.fields.items():
    if type(v) != "float" and type(v) != "int":

      metric.tags.update({k:str(v)})
      metric.fields.pop(k)

  return metric
adonovan commented 4 months ago

This repo is for questions relating to the Go implementation of Starlark, which is embedded within many applications, not with any particular one of those applications. If your question is about Starlark the language, please reopen providing more context on what you mean by "tags" (etc) so that it can be understood without reference to Telegraf. If your question is really about Telegraf's Starlark API, it should be posted in a Telegraf issue tracker or discussion forum.