-
Notifications
You must be signed in to change notification settings - Fork 185
Request: Throw exception when write_api fails #122
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
Hi @datarian, the batching api writes data at a background thread so it's not possible to raise exception (it will raise at background thread). If you would like to immediately know if your data was successfully written then you should use the from influxdb_client import InfluxDBClient, Point
from influxdb_client .client.write_api import SYNCHRONOUS
client = InfluxDBClient(url="http://localhost:9999", token="my-token", org="my-org")
write_api = client.write_api(write_options=SYNCHRONOUS)
write_api.write(bucket="my-bucket", record=data)
client.__del__() Regards |
@bednar I have this issue as well. It's not specific to the batch API either, in fact I think there's a breaking change here. I recently updated from v1.6.0 to v1.8.0 and an exception I was expecting is no longer thrown. On v1.6.0 here is what occurs when I try to connect to a host that does not exist:
And here is that same test after installing v1.8.0:
There's no longer an exception thrown at all when you fail to connect to the host entirely, even when using |
In fact this seems to an issue for any write, not just if the host is missing. Here's me trying to synchronously write to a valid host with everything else invalid on v1.6.0
And here's the same test on v1.8.0:
|
Hi @mdegat01, the client didn't raise exception because the array is empty. If you would like to tests a credentials to write then use:
I've add a test to ensure that client works for you as expect: influxdb-client-python/tests/test_WriteApi.py Line 373 in 1b410f6
home-assistant : home-assistant/core#37710.
Regards |
Thanks @bednar ! That's exactly what I was looking for. You're right, that works great now. Unfortunately it looks like that still throws an 'Invalid Inputs' exception on success, I was hoping to eliminate exception handling from the success path in the code. I created a separate feature request for that for your consideration. But yea, thanks again for your help and the PR 👍 |
@mdegat01 you are welcome |
I am writing an influxdb hook for apache airflow. The relevant code to write a list of lineprotocol-points is as follows:
Unfortunately, write_client.write() does not throw exceptions when something goes wrong. All that happens is a message in the error log. Would it be possible to make write_api raise an exception for such cases? If not, how else would it be possible to know when things go wrong, apart from the logs?
An example of what I see in the logs is this:
[2020-07-01 10:20:29,312] {{logging_mixin.py:112}} INFO - [2020-07-01 10:20:29,311] {{write_api.py:399}} ERROR - The batch item wasn't processed successfully because: (400) Reason: Bad Request HTTP response headers: HTTPHeaderDict({'Content-Type': 'application/json; charset=utf-8', 'X-Platform-Error-Code': 'invalid', 'Date': 'Wed, 01 Jul 2020 10:20:29 GMT', 'Content-Length': '254'})
The text was updated successfully, but these errors were encountered: