Using the default_tags
argument of InfluxDBClient
alters the tags for any write_api by any client
#686
Labels
bug
Something isn't working
Specifications
Code sample to reproduce problem
Expected behavior
When using the
default_tags
argument of theInfluxDBClient
object, I would expect that any record by this client has this tags by default, but that should not affect the tags of other clients.The expected result of the code example should be :
Actual behavior
When using
default_tags
argument of theInfluxDBClient
object, this alters the tags of any existing or newWriteApi
instance, whatever the client instance which created it.The problem arises for instances of
WriteApi
created usingInfluxDBClient.write_api()
with default kwarg values.The result of the code example is :
Additional info
Problem investigation
After investigating the code, the problem is caused by the fact that the default kwarg value for
point_settings
inInfluxDBClient.write_api
is set to a mutablePointSettings
instance, which is modified by the method.As a pointer to the same instance is passed to any call of this method, whatever the
InfluxDBClient
instance making the call, alWriteApi
instances created usingInfluxDBClient.write_api()
use **the same instance ofPointSettings
.Following the code execution, when the
client.write_api()
method is called below, the problem begins :a_client
) instantiates aWriteApi
. As no value is passed forpoint_settings
it uses with thePointSettings
instance which is created when the function is loaded (see e.g. here).PointSettings
instance is consummed by theWriteApi.__init__
_BaseWriteApi.__init__
which itself binds it to its_point_settings
attribute which is modified inplace by passing it the default tags from the client.WriteApi
instance created by usingInfluxDBClient.write_api()
has the default tags ofa_client
!Possible workaround
Always provide a value for the
PointSettings
kwarg of theInfluxDBClient.write_api
method, as in the provided example when creatingw_api_3_2
.Possible fix
Change the implementation so that the default kwarg value is not a mutable, which is a know "gotcha".
Rather, use a pattern where
None
value is passed and in the method bodypoint_settings = point_settings or PointSettings()
.The text was updated successfully, but these errors were encountered: