Skip to content

Timezone autodetection in thin mode is wrong #257

@szpajder

Description

@szpajder
  1. 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 
  1. Is it an error or a hang or a crash?

Error.

  1. 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.timezone

According 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_gmtoff

then it works fine, regardless of whether DST is currently in use or not.

  1. Does your application call init_oracle_client()?

No.

  1. 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) 

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions