oracle / oracle/python-oracledb

Unable to Read Dates with Year `-4712`

Open
#400 4 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

enhancement
Dominant language
Python
Stars
451
Forks
119
PR merge metrics
No merged PRs in 30d

Description

  1. What versions are you using?

oracledb.version: 2.4.1

platform.platform: Windows-10-10.0.17763-SP0
sys.maxsize > 2**32: True
platform.python_version: 3.11.9

Oracle Database 19c Enterprise Edition Release 19.0.0.0.0 - Production

  1. Is it an error or a hang or a crash?

Error

  1. What error(s) or behavior you are seeing?

$ python test.py
Traceback (most recent call last):
File "E:\zzzz\test.py", line 14, in
print(result.fetchall())
^^^^^^^^^^^^^^^^^
File "C:\Users\zzzz\AppData\Local\Programs\Python\Python311\Lib\site-packages\sqlalchemy\engine\result.py", line 1317, in fetchall
return self._allrows()
^^^^^^^^^^^^^^^
File "C:\Users\zzzz\AppData\Local\Programs\Python\Python311\Lib\site-packages\sqlalchemy\engine\result.py", line 548, in _allrows
rows = self._fetchall_impl()
^^^^^^^^^^^^^^^^^^^^^
File "C:\Users\zzzz\AppData\Local\Programs\Python\Python311\Lib\site-packages\sqlalchemy\engine\cursor.py", line 2135, in _fetchall_impl
return self.cursor_strategy.fetchall(self, self.cursor)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "C:\Users\zzzz\AppData\Local\Programs\Python\Python311\Lib\site-packages\sqlalchemy\engine\cursor.py", line 1140, in fetchall
self.handle_exception(result, dbapi_cursor, e)
File "C:\Users\zzzz\AppData\Local\Programs\Python\Python311\Lib\site-packages\sqlalchemy\engine\cursor.py", line 1081, in handle_exception
result.connection._handle_dbapi_exception(
File "C:\Users\zzzz\AppData\Local\Programs\Python\Python311\Lib\site-packages\sqlalchemy\engine\base.py", line 2358, in _handle_dbapi_exception
raise exc_info[1].with_traceback(exc_info[2])
File "C:\Users\zzzz\AppData\Local\Programs\Python\Python311\Lib\site-packages\sqlalchemy\engine\cursor.py", line 1136, in fetchall
rows = dbapi_cursor.fetchall()
^^^^^^^^^^^^^^^^^^^^^^^
File "C:\Users\wegscha\AppData\Local\Programs\Python\Python311\Lib\site-packages\oracledb\cursor.py", line 779, in fetchall
row = fetch_next_row(self)
^^^^^^^^^^^^^^^^^^^^
File "src\oracledb\impl/base/cursor.pyx", line 548, in oracledb.base_impl.BaseCursorImpl.fetch_next_row
File "src\oracledb\impl/base/cursor.pyx", line 260, in oracledb.base_impl.BaseCursorImpl._create_row
File "src\oracledb\impl/thick/var.pyx", line 189, in oracledb.thick_impl.ThickVarImpl._get_scalar_value
File "src\oracledb\impl/thick/var.pyx", line 365, in oracledb.thick_impl.ThickVarImpl._transform_element_to_python
File "src\oracledb\impl/thick/utils.pyx", line 336, in oracledb.thick_impl._convert_to_python
File "datetime.pxd", line 298, in cpython.datetime.datetime_new
ValueError: year -4712 is out of range

  1. Does your application call init_oracle_client()?

Yes.

    sqlalchemy.create_engine(self.sqlalchemy_url, thick_mode=True)
  1. Include a runnable Python script that shows the problem.
import oracledb
import sqlalchemy
from sqlalchemy import text

sqlalchemy_url = f'oracle+oracledb://{config["username"]}:{config["password"]}@{config["host"]}:{config["port"]}/?service_name={config["service_name"]}'
engine = sqlalchemy.create_engine(sqlalchemy_url, thick_mode=True)

query = text("""
SELECT TO_DATE('-4712-01-01','SYYYY-MM-DD') FROM DUAL
""")

with engine.connect() as connection:
    result = connection.execute(query)
    print(result.fetchall())

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with the runnable Python script and the TO_DATE('-4712-01-01','SYYYY-MM-DD') query, then follow the traceback through src/oracledb/impl/thick/var.pyx and src/oracledb/impl/thick/utils.pyx. Verify behavior in Thick mode against Oracle Database 19c; done means fetching this result no longer raises the reported ValueError.

Written by the indexing model from the issue text.

Assessment

Tech stack
python
Domain
databases
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.