Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
### Bug Fixes

1. [#706](https://github.com/influxdata/influxdb-client-python/pull/706): Use logger instead logging.
1. [#540](https://github.com/influxdata/influxdb-client-python/issues/540): Replace invalid tuple type annotations `(str, str, str)` with `Tuple[str, str, str]` in batching callbacks, examples and docs.
1. [#686](https://github.com/influxdata/influxdb-client-python/issues/686): Stop `default_tags` from one client leaking into other clients' `WriteApi` (shared mutable default `PointSettings`).

## 1.50.0 [2026-01-23]
Expand Down
8 changes: 5 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -1183,19 +1183,21 @@ The only exception is **batching** `WriteAPI` (for more info see [Batching](#bat
This is because this API runs in the `background` in a `separate` thread and isn't possible to directly return underlying exceptions.

``` python
from typing import Tuple

from influxdb_client import InfluxDBClient
from influxdb_client.client.exceptions import InfluxDBError


class BatchingCallback(object):

def success(self, conf: (str, str, str), data: str):
def success(self, conf: Tuple[str, str, str], data: str):
print(f"Written batch: {conf}, data: {data}")

def error(self, conf: (str, str, str), data: str, exception: InfluxDBError):
def error(self, conf: Tuple[str, str, str], data: str, exception: InfluxDBError):
print(f"Cannot write batch: {conf}, data: {data} due: {exception}")

def retry(self, conf: (str, str, str), data: str, exception: InfluxDBError):
def retry(self, conf: Tuple[str, str, str], data: str, exception: InfluxDBError):
print(f"Retryable error occurs for batch: {conf}, data: {data} retry: {exception}")


Expand Down
8 changes: 4 additions & 4 deletions examples/http_error_handling.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
"""
import asyncio
import os
from typing import MutableMapping
from typing import MutableMapping, Tuple

from influxdb_client import InfluxDBClient
from influxdb_client.client.exceptions import InfluxDBError
Expand Down Expand Up @@ -47,14 +47,14 @@ def __str__(self):
# To encapsulate functions used in batch writing
class BatchCB(object):

def success(self, conf: (str, str, str), data: str):
def success(self, conf: Tuple[str, str, str], data: str):
print(f"Write success: {conf}, data: {data}")

def error(self, conf: (str, str, str), data: str, exception: InfluxDBError):
def error(self, conf: Tuple[str, str, str], data: str, exception: InfluxDBError):
print(f"\nBatch -> Write failed: {conf}, data: {data}, error: {exception.message}")
report_headers(exception.headers)

def retry(self, conf: (str, str, str), data: str, exception: InfluxDBError):
def retry(self, conf: Tuple[str, str, str], data: str, exception: InfluxDBError):
print(f"Write failed but retryable: {conf}, data: {data}, error: {exception}")


Expand Down
8 changes: 5 additions & 3 deletions examples/write_api_callbacks.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
How to use WriteApi's callbacks to notify about state of background batches.
"""

from typing import Tuple

from influxdb_client import InfluxDBClient, Point
from influxdb_client.client.exceptions import InfluxDBError

Expand All @@ -22,15 +24,15 @@

class BatchingCallback(object):

def success(self, conf: (str, str, str), data: str):
def success(self, conf: Tuple[str, str, str], data: str):
"""Successfully writen batch."""
print(f"Written batch: {conf}, data: {data}")

def error(self, conf: (str, str, str), data: str, exception: InfluxDBError):
def error(self, conf: Tuple[str, str, str], data: str, exception: InfluxDBError):
"""Unsuccessfully writen batch."""
print(f"Cannot write batch: {conf}, data: {data} due: {exception}")

def retry(self, conf: (str, str, str), data: str, exception: InfluxDBError):
def retry(self, conf: Tuple[str, str, str], data: str, exception: InfluxDBError):
"""Retryable error."""
print(f"Retryable error occurs for batch: {conf}, data: {data} retry: {exception}")

Expand Down
8 changes: 5 additions & 3 deletions influxdb_client/client/influxdb_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -240,19 +240,21 @@ def write_api(self, write_options=WriteOptions(), point_settings=None, **kwargs)

.. code-block:: python

from typing import Tuple

from influxdb_client import InfluxDBClient
from influxdb_client.client.exceptions import InfluxDBError


class BatchingCallback(object):

def success(self, conf: (str, str, str), data: str):
def success(self, conf: Tuple[str, str, str], data: str):
print(f"Written batch: {conf}, data: {data}")

def error(self, conf: (str, str, str), data: str, exception: InfluxDBError):
def error(self, conf: Tuple[str, str, str], data: str, exception: InfluxDBError):
print(f"Cannot write batch: {conf}, data: {data} due: {exception}")

def retry(self, conf: (str, str, str), data: str, exception: InfluxDBError):
def retry(self, conf: Tuple[str, str, str], data: str, exception: InfluxDBError):
print(f"Retryable error occurs for batch: {conf}, data: {data} retry: {exception}")


Expand Down
15 changes: 9 additions & 6 deletions influxdb_client/client/util/multiprocessing_helper.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,24 +6,25 @@
"""
import logging
import multiprocessing
from typing import Tuple

from influxdb_client import InfluxDBClient, WriteOptions
from influxdb_client.client.exceptions import InfluxDBError

logger = logging.getLogger('influxdb_client.client.util.multiprocessing_helper')


def _success_callback(conf: (str, str, str), data: str):
def _success_callback(conf: Tuple[str, str, str], data: str):
"""Successfully writen batch."""
logger.debug(f"Written batch: {conf}, data: {data}")


def _error_callback(conf: (str, str, str), data: str, exception: InfluxDBError):
def _error_callback(conf: Tuple[str, str, str], data: str, exception: InfluxDBError):
"""Unsuccessfully writen batch."""
logger.debug(f"Cannot write batch: {conf}, data: {data} due: {exception}")


def _retry_callback(conf: (str, str, str), data: str, exception: InfluxDBError):
def _retry_callback(conf: Tuple[str, str, str], data: str, exception: InfluxDBError):
"""Retryable error."""
logger.debug(f"Retryable error occurs for batch: {conf}, data: {data} retry: {exception}")

Expand Down Expand Up @@ -81,20 +82,22 @@ def main():
How to handle batch events:
.. code-block:: python

from typing import Tuple

from influxdb_client import WriteOptions
from influxdb_client.client.exceptions import InfluxDBError
from influxdb_client.client.util.multiprocessing_helper import MultiprocessingWriter


class BatchingCallback(object):

def success(self, conf: (str, str, str), data: str):
def success(self, conf: Tuple[str, str, str], data: str):
print(f"Written batch: {conf}, data: {data}")

def error(self, conf: (str, str, str), data: str, exception: InfluxDBError):
def error(self, conf: Tuple[str, str, str], data: str, exception: InfluxDBError):
print(f"Cannot write batch: {conf}, data: {data} due: {exception}")

def retry(self, conf: (str, str, str), data: str, exception: InfluxDBError):
def retry(self, conf: Tuple[str, str, str], data: str, exception: InfluxDBError):
print(f"Retryable error occurs for batch: {conf}, data: {data} retry: {exception}")


Expand Down
4 changes: 2 additions & 2 deletions influxdb_client/client/write_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
from enum import Enum
from random import random
from time import sleep
from typing import Union, Any, Iterable, NamedTuple
from typing import Union, Any, Iterable, NamedTuple, Tuple

import reactivex as rx
from reactivex import operators as ops, Observable
Expand Down Expand Up @@ -171,7 +171,7 @@ def __init__(self, key: _BatchItemKey, data, size=1) -> None:
self.size = size
pass

def to_key_tuple(self) -> (str, str, str):
def to_key_tuple(self) -> Tuple[str, str, str]:
return self.key.bucket, self.key.org, self.key.precision

def __str__(self) -> str:
Expand Down
9 changes: 5 additions & 4 deletions tests/test_WriteApiBatching.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import time
import unittest
from collections import namedtuple
from typing import Tuple

import httpretty
import pytest
Expand Down Expand Up @@ -582,7 +583,7 @@ def __init__(self):
self.conf = None
self.data = None

def __call__(self, conf: (str, str, str), data: str):
def __call__(self, conf: Tuple[str, str, str], data: str):
self.conf = conf
self.data = data

Expand Down Expand Up @@ -617,7 +618,7 @@ def __init__(self):
self.data = None
self.error = None

def __call__(self, conf: (str, str, str), data: str, error: InfluxDBError):
def __call__(self, conf: Tuple[str, str, str], data: str, error: InfluxDBError):
self.conf = conf
self.data = data
self.error = error
Expand Down Expand Up @@ -657,7 +658,7 @@ def __init__(self):
self.data = None
self.error = None

def __call__(self, conf: (str, str, str), data: str, error: InfluxDBError):
def __call__(self, conf: Tuple[str, str, str], data: str, error: InfluxDBError):
self.conf = conf
self.data = data
self.error = error
Expand Down Expand Up @@ -704,7 +705,7 @@ def __init__(self):
self.data = None
self.error = None

def __call__(self, conf: (str, str, str), data: str, error: InfluxDBError):
def __call__(self, conf: Tuple[str, str, str], data: str, error: InfluxDBError):
self.count += 1
self.conf = conf
self.data = data
Expand Down