Skip to content

Commit ed67c66

Browse files
authored
Merge pull request #224 merge main into v3
2 parents f7aceb1 + 6b7741d commit ed67c66

File tree

15 files changed

+138
-30
lines changed

15 files changed

+138
-30
lines changed

.github/scripts/increment_version.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66

77
SETUP_PY_PATH = "setup.py"
88
DEFAULT_CHANGELOG_PATH = "CHANGELOG.md"
9+
DEFAULT_YDB_VERSION_FILE = "ydb/ydb_version.py"
910
MARKER = "# AUTOVERSION"
1011

1112

@@ -125,6 +126,10 @@ def add_changelog_version(changelog_path, version: str):
125126
f.write(content)
126127

127128

129+
def set_version_in_ydb_version_file(file_path: str, version: str):
130+
with open(file_path, "w") as f:
131+
f.write('VERSION = "%s"\n' % version)
132+
128133
def main():
129134
parser = argparse.ArgumentParser()
130135
parser.add_argument(
@@ -147,6 +152,7 @@ def main():
147152

148153
new_version = increment_version_at_setup_py(args.setup_py_path, args.inc_type, is_beta)
149154
add_changelog_version(args.changelog_path, new_version)
155+
set_version_in_ydb_version_file(DEFAULT_YDB_VERSION_FILE, new_version)
150156
print(new_version)
151157

152158

.github/workflows/python-publish.yml

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -69,9 +69,6 @@ jobs:
6969
echo "NEW_VERSION=$NEW_VERSION" >> $GITHUB_OUTPUT
7070
echo "New version: $NEW_VERSION" >> $GITHUB_STEP_SUMMARY
7171
72-
git add $SETUP_PY_PATH
73-
git add $CHANGELOG_FILE
74-
7572
- name: Build package
7673
run: python -m build
7774

@@ -93,7 +90,7 @@ jobs:
9390
9491
git config --global user.email "robot@umbrella";
9592
git config --global user.name "robot";
96-
git commit -m "Release: $TAG";
93+
git commit -am "Release: $TAG";
9794
9895
git tag "$TAG"
9996
git push && git push --tags

CHANGELOG.md

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,30 @@
3535
## 3.0.1b1 ##
3636
* start 3.0 beta branch
3737

38+
## 2.13.3 ##
39+
* fixed use transaction object when commit with flag
40+
41+
## 2.13.2 ##
42+
* fix snapshot attribute in class _ResultSet
43+
44+
## 2.13.1 ##
45+
* fixed set version in ydb_version file
46+
47+
## 2.13.0 ##
48+
* fixed in to make compressed backups possible
49+
* Add snapshot to read table responses
50+
51+
## 2.12.4 ##
52+
* Added functions for global change behaviour for compatible with future sdk version: ydb.global_allow_truncated_result and global_allow_split_transactions
53+
54+
## 2.12.3 ##
55+
* Flag for deny split transaction
56+
* Add six package to requirements
57+
* Fixed error while passing date parameter in execute
58+
59+
## 2.12.2 ##
60+
* Fix error of check retriable error for idempotent operations (error exist since 2.12.1)
61+
3862
## 2.12.1 ##
3963
* Supported `TYPE_UNSPECIFIED` item type to scheme ls
4064
* Fixed error while request iam token with bad content type in metadata

requirements.txt

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
1-
aiohttp>=3.7.4,<4.0.0
2-
enum-compat>=0.0.1
31
grpcio>=1.42.0
42
packaging
53
protobuf>=3.13.0,<5.0.0
6-
six<2
4+
pytest==6.2.4
5+
aiohttp==3.7.4

tests/aio/test_tx.py

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ async def test_tx_snapshot_ro(driver, database):
9898

9999

100100
@pytest.mark.asyncio
101-
async def test_split_transactions_deny_split(driver, table_name):
101+
async def test_split_transactions_deny_split_explicit_commit(driver, table_name):
102102
async with ydb.aio.SessionPool(driver, 1) as pool:
103103

104104
async def check_transaction(s: ydb.aio.table.Session):
@@ -118,6 +118,28 @@ async def check_transaction(s: ydb.aio.table.Session):
118118
await pool.retry_operation(check_transaction)
119119

120120

121+
@pytest.mark.asyncio
122+
async def test_split_transactions_deny_split_flag_commit(driver, table_name):
123+
async with ydb.aio.SessionPool(driver, 1) as pool:
124+
125+
async def check_transaction(s: ydb.aio.table.Session):
126+
async with s.transaction(allow_split_transactions=False) as tx:
127+
await tx.execute(
128+
"INSERT INTO %s (id) VALUES (1)" % table_name, commit_tx=True
129+
)
130+
131+
with pytest.raises(RuntimeError):
132+
await tx.execute("INSERT INTO %s (id) VALUES (2)" % table_name)
133+
134+
await tx.commit()
135+
136+
async with s.transaction() as tx:
137+
rs = await tx.execute("SELECT COUNT(*) as cnt FROM %s" % table_name)
138+
assert rs[0].rows[0].cnt == 1
139+
140+
await pool.retry_operation(check_transaction)
141+
142+
121143
@pytest.mark.asyncio
122144
async def test_split_transactions_allow_split(driver, table_name):
123145
async with ydb.aio.SessionPool(driver, 1) as pool:

tests/aio/test_types.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -62,9 +62,9 @@ async def test_types(driver, database, value, ydb_type):
6262
@pytest.mark.parametrize(
6363
"value,ydb_type,result_value",
6464
[
65-
# FIXME: TypeError: 'datetime.date'/'datetime.datetime' object cannot be interpreted as an integer
66-
# (test_today, 'Date', test_today),
65+
# FIXME: TypeError: 'datetime.datetime' object cannot be interpreted as an integer
6766
# (test_dt_today, "Datetime", test_dt_today),
67+
(test_today, "Date", test_today),
6868
(365, "Date", date(1971, 1, 1)),
6969
(3600 * 24 * 365, "Datetime", datetime(1971, 1, 1, 0, 0)),
7070
(test_td, "Interval", test_td),

tests/table/table_test.py

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
import ydb
2+
3+
4+
class TestTable:
5+
def test_create_table_with_not_null_primary_key_by_api(self, driver_sync, database):
6+
table_path = database + "/test_table"
7+
8+
def create_table(session: ydb.Session):
9+
try:
10+
session.drop_table(table_path)
11+
except ydb.issues.SchemeError:
12+
pass
13+
14+
description = (
15+
ydb.TableDescription()
16+
.with_primary_keys("key1")
17+
.with_columns(
18+
ydb.Column("key1", ydb.PrimitiveType.Uint64),
19+
ydb.Column("value", ydb.OptionalType(ydb.PrimitiveType.Utf8)),
20+
)
21+
)
22+
23+
session.create_table(table_path, description)
24+
25+
with ydb.SessionPool(driver_sync) as pool:
26+
pool.retry_operation_sync(create_table)
27+
28+
res = driver_sync.scheme_client.describe_path(table_path)
29+
assert res.type == ydb.scheme.SchemeEntryType.TABLE

tests/table/test_tx.py

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,27 @@ def check_transaction(s: ydb.table.Session):
112112
pool.retry_operation_sync(check_transaction)
113113

114114

115+
def test_split_transactions_deny_split_flag_commit(driver_sync, table_name):
116+
with ydb.SessionPool(driver_sync, 1) as pool:
117+
118+
def check_transaction(s: ydb.table.Session):
119+
with s.transaction(allow_split_transactions=False) as tx:
120+
tx.execute(
121+
"INSERT INTO %s (id) VALUES (1)" % table_name, commit_tx=True
122+
)
123+
124+
with pytest.raises(RuntimeError):
125+
tx.execute("INSERT INTO %s (id) VALUES (2)" % table_name)
126+
127+
tx.commit()
128+
129+
with s.transaction() as tx:
130+
rs = tx.execute("SELECT COUNT(*) as cnt FROM %s" % table_name)
131+
assert rs[0].rows[0].cnt == 1
132+
133+
pool.retry_operation_sync(check_transaction)
134+
135+
115136
def test_split_transactions_allow_split(driver_sync, table_name):
116137
with ydb.SessionPool(driver_sync, 1) as pool:
117138

ydb/_session_impl.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -407,7 +407,8 @@ def bulk_upsert_request_factory(table, rows, column_types):
407407

408408
def wrap_read_table_response(response):
409409
issues._process_response(response)
410-
return convert.ResultSet.from_message(response.result.result_set)
410+
snapshot = response.snapshot if response.HasField("snapshot") else None
411+
return convert.ResultSet.from_message(response.result.result_set, snapshot=snapshot)
411412

412413

413414
class SessionState(object):

ydb/aio/table.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -194,8 +194,6 @@ async def execute(
194194
self, query, parameters=None, commit_tx=False, settings=None
195195
): # pylint: disable=W0236
196196

197-
self._check_split()
198-
199197
return await super().execute(query, parameters, commit_tx, settings)
200198

201199
async def commit(self, settings=None): # pylint: disable=W0236

ydb/convert.py

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -308,15 +308,16 @@ def _unwrap_optionality(column):
308308

309309

310310
class _ResultSet(object):
311-
__slots__ = ("columns", "rows", "truncated")
311+
__slots__ = ("columns", "rows", "truncated", "snapshot")
312312

313-
def __init__(self, columns, rows, truncated):
313+
def __init__(self, columns, rows, truncated, snapshot=None):
314314
self.columns = columns
315315
self.rows = rows
316316
self.truncated = truncated
317+
self.snapshot = snapshot
317318

318319
@classmethod
319-
def from_message(cls, message, table_client_settings=None):
320+
def from_message(cls, message, table_client_settings=None, snapshot=None):
320321
rows = []
321322
# prepare columnn parsers before actuall parsing
322323
column_parsers = []
@@ -343,12 +344,12 @@ def from_message(cls, message, table_client_settings=None):
343344
unwrapped_type, value, table_client_settings
344345
)
345346
rows.append(row)
346-
return cls(message.columns, rows, message.truncated)
347+
return cls(message.columns, rows, message.truncated, snapshot)
347348

348349
@classmethod
349-
def lazy_from_message(cls, message, table_client_settings=None):
350+
def lazy_from_message(cls, message, table_client_settings=None, snapshot=None):
350351
rows = _LazyRows(message.rows, table_client_settings, message.columns)
351-
return cls(message.columns, rows, message.truncated)
352+
return cls(message.columns, rows, message.truncated, snapshot)
352353

353354

354355
ResultSet = _ResultSet

ydb/export.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,7 @@ def __init__(self):
131131
self.secret_key = None
132132
self.number_of_retries = 0
133133
self.storage_class = None
134-
self.compression = None
134+
self.export_compression = None
135135

136136
def with_scheme(self, scheme):
137137
self.scheme = scheme
@@ -141,8 +141,8 @@ def with_storage_class(self, storage_class):
141141
self.storage_class = storage_class
142142
return self
143143

144-
def with_compression(self, compression):
145-
self.compression = compression
144+
def with_export_compression(self, compression):
145+
self.export_compression = compression
146146
return self
147147

148148
def with_bucket(self, bucket):
@@ -225,8 +225,8 @@ def _export_to_s3_request_factory(settings):
225225
if settings.number_of_retries > 0:
226226
request.settings.number_of_retries = settings.number_of_retries
227227

228-
if settings.compression is not None:
229-
request.settings.compression = settings.compression
228+
if settings.export_compression is not None:
229+
request.settings.compression = settings.export_compression
230230

231231
for source_path, destination_prefix in settings.items:
232232
request.settings.items.add(

ydb/table.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2311,6 +2311,8 @@ def execute(self, query, parameters=None, commit_tx=False, settings=None):
23112311
"""
23122312

23132313
self._check_split()
2314+
if commit_tx:
2315+
self._set_finish(self._COMMIT)
23142316

23152317
return self._driver(
23162318
_tx_ctx_impl.execute_request_factory(

ydb/types.py

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,13 +13,20 @@
1313
_EPOCH = datetime(1970, 1, 1)
1414

1515

16-
def _from_date_number(x, table_client_settings):
16+
def _from_date(x, table_client_settings):
1717
if (
1818
table_client_settings is not None
1919
and table_client_settings._native_date_in_result_sets
2020
):
21-
return date.fromordinal(x + date(1970, 1, 1).toordinal())
22-
return x
21+
return _EPOCH.date() + timedelta(days=x.uint32_value)
22+
return x.uint32_value
23+
24+
25+
def _to_date(pb, value):
26+
if isinstance(value, date):
27+
pb.uint32_value = (value - _EPOCH.date()).days
28+
else:
29+
pb.uint32_value = value
2330

2431

2532
def _from_datetime_number(x, table_client_settings):
@@ -113,8 +120,9 @@ class PrimitiveType(enum.Enum):
113120
UUID = (_apis.primitive_types.UUID, None, _to_uuid, _from_uuid)
114121
Date = (
115122
_apis.primitive_types.DATE,
116-
"uint32_value",
117-
_from_date_number,
123+
None,
124+
_from_date,
125+
_to_date,
118126
)
119127
Datetime = (
120128
_apis.primitive_types.DATETIME,

ydb/ydb_version.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
VERSION = "2.10.0"
1+
VERSION = "2.13.3"

0 commit comments

Comments
 (0)