@@ -51,6 +51,7 @@ def __init__(self, write_type: WriteType = WriteType.batching,
5151 max_retry_time = 180_000 ,
5252 exponential_base = 2 ,
5353 max_close_wait = 300_000 ,
54+ write_precision = DEFAULT_WRITE_PRECISION ,
5455 write_scheduler = ThreadPoolScheduler (max_workers = 1 )) -> None :
5556 """
5657 Create write api configuration.
@@ -66,7 +67,8 @@ def __init__(self, write_type: WriteType = WriteType.batching,
6667 :param max_retry_delay: the maximum delay between each retry attempt in milliseconds
6768 :param max_retry_time: total timeout for all retry attempts in milliseconds, if 0 retry is disabled
6869 :param exponential_base: base for the exponential retry delay
69- :parama max_close_wait: the maximum time to wait for writes to be flushed if close() is called
70+ :param max_close_wait: the maximum time to wait for writes to be flushed if close() is called
71+ :param write_precision: the time precision for the data written to InfluxDB.
7072 :param write_scheduler:
7173 """
7274 self .write_type = write_type
@@ -80,6 +82,7 @@ def __init__(self, write_type: WriteType = WriteType.batching,
8082 self .exponential_base = exponential_base
8183 self .write_scheduler = write_scheduler
8284 self .max_close_wait = max_close_wait
85+ self .write_precision = write_precision
8386
8487 def to_retry_strategy (self , ** kwargs ):
8588 """
@@ -290,7 +293,7 @@ def write(self, bucket: str, org: str = None,
290293 str , Iterable ['str' ], Point , Iterable ['Point' ], dict , Iterable ['dict' ], bytes , Iterable ['bytes' ],
291294 Observable , NamedTuple , Iterable ['NamedTuple' ], 'dataclass' , Iterable ['dataclass' ]
292295 ] = None ,
293- write_precision : WritePrecision = DEFAULT_WRITE_PRECISION , ** kwargs ) -> Any :
296+ write_precision : WritePrecision = None , ** kwargs ) -> Any :
294297 """
295298 Write time-series data into InfluxDB.
296299
@@ -360,7 +363,10 @@ def write(self, bucket: str, org: str = None,
360363 org = get_org_query_param (org = org , client = self ._influxdb_client )
361364
362365 self ._append_default_tags (record )
363-
366+
367+ if write_precision is None :
368+ write_precision = self ._write_options .write_precision
369+
364370 if self ._write_options .write_type is WriteType .batching :
365371 return self ._write_batching (bucket , org , record ,
366372 write_precision , ** kwargs )
@@ -443,8 +449,11 @@ def __del__(self):
443449 pass
444450
445451 def _write_batching (self , bucket , org , data ,
446- precision = DEFAULT_WRITE_PRECISION ,
452+ precision = None ,
447453 ** kwargs ):
454+ if precision is None :
455+ precision = self ._write_options .write_precision
456+
448457 if isinstance (data , bytes ):
449458 _key = _BatchItemKey (bucket , org , precision )
450459 self ._subject .on_next (_BatchItem (key = _key , data = data ))
@@ -454,7 +463,8 @@ def _write_batching(self, bucket, org, data,
454463 precision , ** kwargs )
455464
456465 elif isinstance (data , Point ):
457- self ._write_batching (bucket , org , data .to_line_protocol (), data .write_precision , ** kwargs )
466+ write_precision = data .write_precision if data .write_precision is not None else precision
467+ self ._write_batching (bucket , org , data .to_line_protocol (), write_precision , ** kwargs )
458468
459469 elif isinstance (data , dict ):
460470 self ._write_batching (bucket , org , Point .from_dict (data , write_precision = precision , ** kwargs ),
0 commit comments