feat: support partial writes#213
Conversation
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #213 +/- ##
==========================================
+ Coverage 76.05% 77.45% +1.40%
==========================================
Files 37 37
Lines 2543 2710 +167
==========================================
+ Hits 1934 2099 +165
- Misses 609 611 +2 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
There was a problem hiding this comment.
Pull request overview
This PR adds partial-write support to the InfluxDB 3 Python client by introducing a structured partial-write exception and by finalizing write endpoint selection logic to support both the V2 compatibility endpoint (/api/v2/write) and the V3 LP endpoint (/api/v3/write_lp). It also exposes new write configuration surfaces (options, constructor kwargs, and env vars) and updates tests and documentation accordingly.
Changes:
- Introduces
InfluxDBPartialWriteError/InfluxDBPartialWriteLineErrorand structured parsing/formatting of partial-write responses. - Adds write routing and option semantics via
use_v2_api,accept_partial, andno_sync(including validation and env/kwargs wiring). - Updates unit/integration tests and README/CHANGELOG to cover and document the new behaviors.
Reviewed changes
Copilot reviewed 12 out of 12 changed files in this pull request and generated 2 comments.
Show a summary per file
| File | Description |
|---|---|
influxdb_client_3/write_client/client/write_api.py |
Adds default write options (accept_partial, use_v2_api), per-request option resolution, and validation before dispatch. |
influxdb_client_3/write_client/service/write_service.py |
Routes requests to /api/v2/write vs /api/v3/write_lp, adds partial-write error raising, and improves 405 compatibility errors. |
influxdb_client_3/exceptions/exceptions.py |
Adds partial-write detection/parsing helpers and the new structured partial-write exception types. |
influxdb_client_3/exceptions/__init__.py |
Exports the new partial-write exception types. |
influxdb_client_3/__init__.py |
Adds env vars + constructor kwargs for new write booleans and updates env parsing helper. |
README.md |
Documents partial-write handling and endpoint compatibility configuration. |
CHANGELOG.md |
Records the new feature and option semantics. |
tests/test_api_client.py |
Expands error parsing tests to assert structured partial-write errors and fallback behavior. |
tests/test_influxdb_client_3.py |
Updates default option assertions, env/kwargs boolean parsing tests, and adds async multi-precision list behavior test. |
tests/test_influxdb_client_3_integration.py |
Updates integration coverage to expect InfluxDBPartialWriteError on partial write failures. |
tests/test_write_local_server.py |
Adds/updates local-server routing tests for use_v2_api, accept_partial, and no_sync validation. |
tests/test_polars.py |
Updates mock expectations to include new write parameters. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| @@ -157,13 +159,40 @@ def post_write_with_http_info(self, org, bucket, body, **kwargs): # noqa: E501, | |||
| _request_timeout=local_var_params.get('_request_timeout'), | |||
| collection_formats={}, | |||
| urlopen_kw=kwargs.get('urlopen_kw', None)) | |||
| if local_var_params.get('async_req'): | |||
| original_get = result.get | |||
|
|
|||
| def translated_get(timeout=None): | |||
| try: | |||
| return original_get(timeout=timeout) | |||
| except ApiException as e: | |||
| raise self._translate_write_exception(e, use_v2_api) | |||
|
|
|||
| result.get = translated_get | |||
| return result | |||
| except ApiException as e: | |||
| no_sync = 'no_sync' in local_var_params and local_var_params['no_sync'] | |||
| if no_sync and e.status == HTTPStatus.METHOD_NOT_ALLOWED: | |||
| message = "Server doesn't support write with no_sync=true " \ | |||
| "(supported by InfluxDB 3 Core/Enterprise servers only)." | |||
| raise ApiException(status=0, reason=message) | |||
| raise e | |||
| raise self._translate_write_exception(e, use_v2_api) | |||
|
|
|||
|
Is this Partial Write logic being considered or has it been implemented in Telegraf? |
Proposed Changes
This PR adds partial-write support in the Python client and finalizes write API selection behavior for product compatibility.
Feature highlights:
InfluxDBPartialWriteErrorwith per-line details:line_numbererror_messageoriginal_lineaccept_partialdefaults totrue(server default behavior)accept_partial=falseis sent only when partial writes are explicitly disableduse_v2_apiroutes writes between:/api/v2/write/api/v3/write_lpDefault behavior and option semantics:
use_v2_api=true).no_syncrequiresuse_v2_api=falseand is rejected otherwise.accept_partialapplies only to V3 endpoint writes and is not used on V2 endpoint writes.Configuration surfaces:
accept_partial,use_v2_api,no_syncwrite_accept_partial,write_use_v2_api,write_no_syncINFLUX_WRITE_ACCEPT_PARTIAL,INFLUX_WRITE_USE_V2_API,INFLUX_WRITE_NO_SYNCSee Partial writes for reference.
Example (partial-write handling):
Example (enable V3 write options):
Checklist