Skip to content

feat: support partial writes#210

Draft
alespour wants to merge 5 commits intomainfrom
feat/partial-writes
Draft

feat: support partial writes#210
alespour wants to merge 5 commits intomainfrom
feat/partial-writes

Conversation

@alespour
Copy link
Copy Markdown
Contributor

@alespour alespour commented May 5, 2026

Proposed Changes

Adds partial-write support with structured error details in InfluxDBPartialWriteError, including per-line line_number, error_message, and original_line so callers can decide whether to drop/retry/fix specific lines in a batch.

This also aligns write routing with the rollout contract:

  • Default write endpoint is now /api/v3/write_lp
  • accept_partial defaults to True (server default behavior)
  • accept_partial=false is sent only when partial writes are explicitly disabled
  • New compatibility option use_v2_api routes writes to /api/v2/write for Clustered/v2-compatible backends

Configuration surfaces now include:

  • Write option: accept_partial, use_v2_api
  • Client config / connection string keys: write_accept_partial, write_use_v2_api
  • Environment variables: INFLUX_WRITE_ACCEPT_PARTIAL, INFLUX_WRITE_USE_V2_API

Validation:

  • use_v2_api=True with no_sync=True is rejected before request dispatch.

See Partial writes in InfluxDB documentation.

Example:

client = InfluxDBClient3(
    host=host,
    database=database,
    token=token
)

try:
    client.write(lp)  # accept_partial=True by default
except InfluxDBPartialWriteError as err:
    for line_err in err.line_errors:
        print(
            f"line {line_err.line_number} failed: "
            f"{line_err.error_message} ({line_err.original_line})"
        )
except Exception as err:
    print(err)

Optional v2 compatibility mode:

client = InfluxDBClient3(
    host=host,
    database=database,
    token=token,
    write_use_v2_api=True,
)

client.write(lp)

Checklist

  • CHANGELOG.md updated
  • Rebased/mergeable
  • A test has been added if appropriate
  • Tests pass
  • Commit messages are conventional

@codecov
Copy link
Copy Markdown

codecov Bot commented May 5, 2026

Codecov Report

❌ Patch coverage is 92.13483% with 14 lines in your changes missing coverage. Please review.
✅ Project coverage is 75.96%. Comparing base (a1e03da) to head (b514d94).

Files with missing lines Patch % Lines
influxdb_client_3/exceptions/exceptions.py 90.75% 11 Missing ⚠️
influxdb_client_3/__init__.py 86.36% 3 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main     #210      +/-   ##
==========================================
+ Coverage   75.17%   75.96%   +0.79%     
==========================================
  Files          35       35              
  Lines        2417     2559     +142     
==========================================
+ Hits         1817     1944     +127     
- Misses        600      615      +15     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR adds client-side support for InfluxDB v3 partial writes by introducing a structured InfluxDBPartialWriteError (with per-line error details) and updates write routing/options to default to the v3 /api/v3/write_lp endpoint while allowing an opt-in v2 compatibility route (/api/v2/write).

Changes:

  • Add InfluxDBPartialWriteError/InfluxDBPartialWriteLineError and parse v3 partial-write error payloads into structured line-level failures.
  • Default write routing to /api/v3/write_lp, add accept_partial (default True) and use_v2_api (default False) write options with env/kwarg support.
  • Update unit/integration tests and README to cover the new defaults and new error/option behavior.

Reviewed changes

Copilot reviewed 11 out of 11 changed files in this pull request and generated 2 comments.

Show a summary per file
File Description
tests/test_write_local_server.py Updates expected endpoints/query params for v3 defaults; adds coverage for accept_partial and use_v2_api routing/validation.
tests/test_polars.py Adjusts mocked write call expectations to include new write kwargs.
tests/test_influxdb_client_3.py Verifies new default write options and env parsing for accept_partial/use_v2_api.
tests/test_influxdb_client_3_integration.py Updates integration test to expect InfluxDBPartialWriteError for invalid LP scenarios.
tests/test_api_client.py Expands API error parsing tests to validate partial-write parsing and typed/raw fallback behavior.
README.md Documents partial-write handling and v2 compatibility mode configuration.
influxdb_client_3/write_client/service/write_service.py Routes writes to v3 by default, adds v2 compatibility routing and partial-write error translation.
influxdb_client_3/write_client/client/write_api.py Adds new defaults/options, validates invalid combinations, and threads new params through write dispatch.
influxdb_client_3/exceptions/exceptions.py Implements partial-write detection/parsing, structured error classes, and improved message formatting.
influxdb_client_3/exceptions/init.py Re-exports the new partial-write exception types.
influxdb_client_3/init.py Adds env/kwarg configuration keys for new write options and updates error imports/handling.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread influxdb_client_3/__init__.py
Comment thread influxdb_client_3/__init__.py Outdated
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 11 out of 11 changed files in this pull request and generated 2 comments.


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

use_v2_api = 'use_v2_api' in local_var_params and local_var_params['use_v2_api']
if not use_v2_api and e.status == HTTPStatus.METHOD_NOT_ALLOWED:
message = "Server doesn't support v3 write API. Set use_v2_api=True for v2 compatibility endpoint."
raise ApiException(status=0, reason=message)
"""Structured partial-write error with per-line failures."""

def __init__(self, response: HTTPResponse, message: str, line_errors: List[InfluxDBPartialWriteLineError]):
super().__init__(response=response)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants