Skip to content

fix: parsing date fails due to thread race #477

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

Merged
merged 1 commit into from
Aug 8, 2022
Merged
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
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
## 1.32.0[unreleased]

### Bug Fixes
1. [#477](https://github.com/influxdata/influxdb-client-python/pull/477): parsing date fails due to thread race

## 1.31.0 [2022-07-29]

### Features
Expand Down
19 changes: 13 additions & 6 deletions influxdb_client/client/util/date_utils.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,14 @@
"""Utils to get right Date parsing function."""
import datetime
import threading
from datetime import timezone as tz

from dateutil import parser

date_helper = None

lock_ = threading.Lock()


class DateHelper:
"""
Expand Down Expand Up @@ -79,11 +82,15 @@ def get_date_helper() -> DateHelper:
"""
global date_helper
if date_helper is None:
date_helper = DateHelper()
try:
import ciso8601
date_helper.parse_date = ciso8601.parse_datetime
except ModuleNotFoundError:
date_helper.parse_date = parser.parse
with lock_:
# avoid duplicate initialization
if date_helper is None:
_date_helper = DateHelper()
try:
import ciso8601
_date_helper.parse_date = ciso8601.parse_datetime
except ModuleNotFoundError:
_date_helper.parse_date = parser.parse
date_helper = _date_helper

return date_helper