- Notifications
You must be signed in to change notification settings - Fork 94
Closed
Labels
Description
- What versions are you using?
Oracle 19c
platform.platform: Linux-6.4.10-arch1-1-x86_64-with-glibc2.38 sys.maxsize > 2**32: True platform.python_version: 3.11.3 - Is it an error or a hang or a crash?
Error.
- What error(s) or behavior you are seeing?
$ date Wed Nov 22 16:27:47 CET 2023 $ python test.py (datetime.datetime(2023, 11, 22, 17, 27, 52), '+02:00') test.py is a script listed below. The current system timezone is CET (ie. winter time, which is +01:00) however oracledb autodetects it as +02:00 (summer time, CEST), regardless of the time of the year. As a result, all timestamps read from a database are OK during summer time, but off by 1 hour in winter time.
This is due to an incorrect autodetection logic in _get_alter_timezone_statement():
if tz_repr is None: timezone = -time.altzone if time.daylight else -time.timezoneAccording to the docs, time.daylight indicates whether DST is defined for the current timezone, ie. if there is a time, past, present or future when daylight saving time applies. It does not indicate that DST is currently in use.
If I replace the above line with:
timezone = time.localtime().tm_gmtoffthen it works fine, regardless of whether DST is currently in use or not.
- Does your application call init_oracle_client()?
No.
- Include a runnable Python script that shows the problem.
import oracledb with oracledb.connect(host='...', port=..., user='...',password='...',sid='...') as conn: with conn.cursor() as cursor: for row in cursor.execute('select current_date, sessiontimezone from dual'): print(row)