Skip to content

Using params in flux queries with Python influxdb_client #285

@rburchDev

Description

@rburchDev

It seems that there may be issues with passing params with query_data_frame(). See below code example:

client = InfluxDBClient(url="localhost:5000", token="", timeout=100000, retries=0, enable_gzip=True, profilers="query, operator")
query_api = client.query_api()

ver = "data"  # This variable would come from a function 
p = {
    "_pVersion": ver,
}
df = query_api.query_data_frame('''from(bucket:"db")
                                |> range(start: -200d)
                                |> pivot(rowKey:["_time"], columnKey: ["_field"], valueColumn: "_value")
                                |> filter(fn: (r) => r._measurement == "test_result")
                                |> filter(fn: (r) => r.version == _pVersion)
                                |> keep(columns: ["_time", "test", "run", "status_tag", "duration_sec", "version"])''',
                                params=p
                                )

Expected behavior:
I expect that this query would run as if I was passing the variable inline. like such:

client = InfluxDBClient(url="localhost:5000", token="", timeout=100000, retries=0, enable_gzip=True, profilers="query, operator")
query_api = client.query_api()

ver = "data"  # This variable would come from a function 

df = query_api.query_data_frame(f'''from(bucket:"db")
                                |> range(start: -200d)
                                |> pivot(rowKey:["_time"], columnKey: ["_field"], valueColumn: "_value")
                                |> filter(fn: (r) => r._measurement == "test_result")
                                |> filter(fn: (r) => r.version == "{ver}")
                                |> keep(columns: ["_time", "test", "run", "status_tag", "duration_sec", "version"])'''
                                )

Actual behavior:
I am getting the below error:
HTTP response body: b'{"error":"type error 5:67-5:76: undefined identifier \\"_pVersion\\""}\n'

Specifications:

  • Client Version: 1.19.0
  • InfluxDB Version: 1.8.6
  • Platform: MacOS

Please see my Stackoverflow post for additional data: https://stackoverflow.com/questions/68385739/using-params-in-flux-queries-with-python-influxdb-client?noredirect=1#comment120860080_68385739

Metadata

Metadata

Assignees

No one assigned

    Labels

    wontfixThis will not be worked on

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions