Repository navigation
fix: partial write error handling - #239
NguyenHoangSon96 wants to merge 10 commits into
Conversation
There was a problem hiding this comment.
Pull request overview
This PR refactors write error handling to better distinguish partial-write errors from generic write failures by parsing JSON error bodies and conditionally raising InfluxDBPartialWriteError only when accept_partial is enabled and the response matches the expected “rejected rows” list format.
Changes:
- Update write exception translation to parse JSON bodies and format per-line rejection details for partial writes.
- Adjust sync REST client response decoding to normalize empty bodies to
None. - Expand and update tests to cover partial-write detection, message formatting, and fallback behaviors.
Reviewed changes
Copilot reviewed 5 out of 5 changed files in this pull request and generated 4 comments.
Show a summary per file
| File | Description |
|---|---|
tests/test_write_api.py |
Adds broader unit coverage for write-error classification and fallback messaging; updates existing error-translation tests. |
tests/test_influxdb_client_3_integration.py |
Loosens assertion on v3 error message content and narrows the tested accept_partial configuration. |
influxdb_client_3/write_client/client/write_api.py |
Implements new JSON parsing and partial-write detection/formatting in _translate_write_exception. |
influxdb_client_3/write_client/_sync/rest_client.py |
Avoids decoding empty bodies and normalizes empty data to None. |
influxdb_client_3/exceptions/exceptions.py |
Changes exception message handling and updates partial-write error types/constructors. |
Suppressed comments (1)
influxdb_client_3/exceptions/exceptions.py:69
- These PEP 604 union annotations (
int | None, etc.) will fail to parse on Python <3.10. UseOptional[...](withOptionalimported fromtyping) to preserve compatibility.
class InfluxDBPartialWriteLineError:
line_number: int | None
error_message: str | None
original_line: str | None
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
0e798b1 to
3352e90
Compare
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 6 out of 6 changed files in this pull request and generated 2 comments.
Suppressed comments (2)
influxdb_client_3/exceptions/exceptions.py:5
- Python 3.9 is still in the CI matrix, but this module now uses PEP 604 union syntax elsewhere (
int | None), so you’ll needOptionalavailable for 3.9-compatible type annotations.
from typing import List
influxdb_client_3/exceptions/exceptions.py:69
int | None/str | Nonetype syntax is a Python 3.10+ feature and will raise a SyntaxError on Python 3.9 (which is still in.github/workflows/pylint.yml). UseOptional[...]instead for compatibility.
class InfluxDBPartialWriteLineError:
line_number: int | None
error_message: str | None
original_line: str | None
Codecov Report❌ Patch coverage is Additional details and impacted files@@ Coverage Diff @@
## main #239 +/- ##
==========================================
+ Coverage 87.78% 87.99% +0.20%
==========================================
Files 28 28
Lines 2072 2049 -23
==========================================
- Hits 1819 1803 -16
+ Misses 253 246 -7 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
1ea4183 to
1c5111d
Compare
28581e6 to
4f769ef
Compare
bednar
left a comment
There was a problem hiding this comment.
I found five issues that need to be addressed before approval.
dc587df to
90321e4
Compare
d4c9bd5 to
8b146c8
Compare
8b146c8 to
6cf2352
Compare
|
@karel-rehor |
karel-rehor
left a comment
There was a problem hiding this comment.
I have some concerns about missed opportunities to improve and simplify the API. This is of course open for discussion.
wip: refactor
abde96f to
a7186a6
Compare
There was a problem hiding this comment.
🟡 Changes recommended
Critical import and exception-hierarchy issues remain, along with additional error-handling and compatibility findings.
9 open findings
Fix undefined InfluxDB query exception import · New Import write_exceptions from the exceptions package · New Make partial-write exceptions inherit from write exceptions · New Fix invalid exception import and constructor arguments · New Lint job no longer covers all supported Python versions · New Require line error messages to be non-empty strings · New Preserve the response in fallback exceptions · New Use accepts instead of except in changelog entry · New Correct write_exceptions module path in docstring example · New
3 resolved since last review
🧠 Review effort: Lite
Give feedback about Copilot approvals in this survey to enter a drawing for a $150 gift card.
| strategy: | ||
| matrix: | ||
| python-version: ["3.8", "3.9", "3.10", "3.11"] | ||
| python-version: ["3.14"] |
There was a problem hiding this comment.
Hi Karel, do you agree with this suggestion?
52e3854 to
f677af1
Compare
|
Hi @karel-rehor |
karel-rehor
left a comment
There was a problem hiding this comment.
So far the refactoring looks great.
I still have a suggestion for revising the name of the InfluxDBPartialWriteLineException class, which seems to be inaccurately named.
It involves a bit of linguistic jargon, but linguistics has long been a bit of a hobby.
|
|
||
|
|
||
| @dataclass(frozen=True) | ||
| class InfluxDBPartialWriteLineException: |
There was a problem hiding this comment.
After seeing similar classes to this in other libraries, it now occurs to me why the name seems odd.
Lexicologically in English most often all modifying adjectival seme (A) precede the seme indicating the substative nucleus (N) of the phrase, which indicates its wider contextual semantic role. e.g. "Big (A) blue (A) french (A) poodle (N)". Wider contextual semantic roles: "A big blue french poodle ate my Siamese cat." or "My girlfriend ran over a big blue french poodle." In either case the nucleus "poodle" occurs last.
The name InfluxDBParialWriteLineException, with the seme "Exception" occurring last, implies that the substantive nucleus of the class and the objects from which it is derived will assume the semantic role of an exception. e.g. "Influx(A) DB(A) Partial(A) Write (A) Line (A) Exception (N)". In other words it implies that it will encapsulate exceptions occurring from a Line.
But I believe the role of this class is more to encapsulate a complex line of information derived from an exception and not to be an exception.
So a more accurate name would need the seme for the nucleus to be "Line" and for this to be in the last place, which would probably best be "Influx(A) DB(A) Partial(AV) Write(A) Exception(A) Line(N)" or InfluxDBPartialWriteExceptionLine.
Perhaps this is may seem trivial at this phase. But I think it makes the intention behind the code clearer.
I'm unsure of the how word order works in Vietnamese (the current order may be a transfer of lexical rules), but in Czech it is perfectly possible to have an order like (A)-(N)-(A). Still in English, which implies programming languages derived from English, the order of words or of seme must be more strictly observed.
We may want to review this in other updated libraries.
There was a problem hiding this comment.
No, I have no problem with that.
I changed the class name to InfluxDBPartialWriteExceptionLine.



Closes #
Proposed Changes
The current exception classes hierarchy are
InfluxDBError->InfluxDBPartialWriteErrorandApiExceptionInfluxDBErrorthere is an important function_get_message(self, response), this function will run everytime a subclass ofInfluxDBErroris initialized, inside this function there is a quite heavy function will run, that is_parse_partial_write_line_error_info(data), so when a partial write error occurs_get_message(self, response)will be called at least twice.Some issues:
InfluxDBErrorwill have the same way of parsing the error messages like we do in_get_message(self, response)function is not correct... I think.We can try to make everything work more efficiently as possible with the current exception classes implementation, but I still feel It very wrong on the architecture and design perspective.
What I'm trying to do right now is moving all logic inside exception classes to WriteApi class (or wherever than inside exception classes) and making them as lightweight as possible. They should only carry information about the errors;
Checklist