Skip to content
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
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
* Fixed error while passing date parameter in execute

## 2.12.2 ##
* Fix error of check retriable error for idempotent operations (error exist since 2.12.1)

Expand Down
4 changes: 2 additions & 2 deletions tests/aio/test_types.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,9 +62,9 @@ async def test_types(driver, database, value, ydb_type):
@pytest.mark.parametrize(
"value,ydb_type,result_value",
[
# FIXME: TypeError: 'datetime.date'/'datetime.datetime' object cannot be interpreted as an integer
# (test_today, 'Date', test_today),
# FIXME: TypeError: 'datetime.datetime' object cannot be interpreted as an integer
# (test_dt_today, "Datetime", test_dt_today),
(test_today, "Date", test_today),
(365, "Date", date(1971, 1, 1)),
(3600 * 24 * 365, "Datetime", datetime(1971, 1, 1, 0, 0)),
(test_td, "Interval", test_td),
Expand Down
19 changes: 14 additions & 5 deletions ydb/types.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@

_SECONDS_IN_DAY = 60 * 60 * 24
_EPOCH = datetime(1970, 1, 1)

if six.PY3:
_from_bytes = None
else:
Expand All @@ -20,13 +21,20 @@ def _from_bytes(x, table_client_settings):
return _utilities.from_bytes(x)


def _from_date_number(x, table_client_settings):
def _from_date(x, table_client_settings):
if (
table_client_settings is not None
and table_client_settings._native_date_in_result_sets
):
return date.fromordinal(x + date(1970, 1, 1).toordinal())
return x
return _EPOCH.date() + timedelta(days=x.uint32_value)
return x.uint32_value


def _to_date(pb, value):
if isinstance(value, date):
pb.uint32_value = (value - _EPOCH.date()).days
else:
pb.uint32_value = value


def _from_datetime_number(x, table_client_settings):
Expand Down Expand Up @@ -122,8 +130,9 @@ class PrimitiveType(enum.Enum):
UUID = (_apis.primitive_types.UUID, None, _to_uuid, _from_uuid)
Date = (
_apis.primitive_types.DATE,
"uint32_value",
_from_date_number,
None,
_from_date,
_to_date,
)
Datetime = (
_apis.primitive_types.DATETIME,
Expand Down