Skip to content

Commit 5056bce

Browse files
committed
backward compatibility for import: check if db version <= 2.3.6, then disable import of write-hooks
1 parent 921eae3 commit 5056bce

File tree

1 file changed

+17
-10
lines changed

1 file changed

+17
-10
lines changed

rethinkdb/_import.py

Lines changed: 17 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -301,13 +301,13 @@ def restore_indexes(self, warning_queue):
301301
exception_type, exception_class, trcback = sys.exc_info()
302302
warning_queue.put((exception_type, exception_class, traceback.extract_tb(trcback), self._source.name))
303303

304-
self.query_runner(
305-
"Write hook from: %s.%s" %
306-
(self.db, self.table), query.db(
307-
self.db).table(
308-
self.table).get_write_hook())
309-
try:
310-
if self.write_hook:
304+
if self.write_hook:
305+
self.query_runner(
306+
"Write hook from: %s.%s" %
307+
(self.db, self.table), query.db(
308+
self.db).table(
309+
self.table).get_write_hook())
310+
try:
311311
self.query_runner(
312312
"drop hook: %s.%s" % (self.db, self.table),
313313
query.db(self.db).table(self.table).set_write_hook(None)
@@ -316,9 +316,9 @@ def restore_indexes(self, warning_queue):
316316
"create hook: %s.%s:%s" % (self.db, self.table, self.write_hook),
317317
query.db(self.db).table(self.table).set_write_hook(self.write_hook["function"])
318318
)
319-
except RuntimeError:
320-
exception_type, exception_class, trcback = sys.exc_info()
321-
warning_queue.put((exception_type, exception_class, traceback.extract_tb(trcback), self._source.name))
319+
except RuntimeError:
320+
exception_type, exception_class, trcback = sys.exc_info()
321+
warning_queue.put((exception_type, exception_class, traceback.extract_tb(trcback), self._source.name))
322322

323323
def batches(self, batch_size=None, warning_queue=None):
324324

@@ -1342,6 +1342,7 @@ def parse_sources(options, files_ignored=None):
13421342
def parse_info_file(path):
13431343
primary_key = None
13441344
indexes = []
1345+
write_hook = None
13451346
with open(path, 'r') as info_file:
13461347
metadata = json.load(info_file)
13471348
if "primary_key" in metadata:
@@ -1352,6 +1353,8 @@ def parse_info_file(path):
13521353
write_hook = metadata["write_hook"]
13531354
return primary_key, indexes, write_hook
13541355

1356+
has_write_hooks = utils_common.check_minimum_version(options, '2.3.7', False)
1357+
13551358
sources = set()
13561359
if files_ignored is None:
13571360
files_ignored = []
@@ -1385,6 +1388,8 @@ def parse_info_file(path):
13851388
indexes = info_indexes
13861389
if write_hook is None:
13871390
write_hook = info_write_hook
1391+
if write_hook and not has_write_hooks:
1392+
raise Exception('this RDB version doesn\'t support write-hooks')
13881393

13891394
sources.add(
13901395
table_type(
@@ -1449,6 +1454,8 @@ def parse_info_file(path):
14491454
files_ignored.append(os.path.join(root, filename))
14501455
else:
14511456
primary_key, indexes, write_hook = parse_info_file(info_path)
1457+
if write_hook and not has_write_hooks:
1458+
raise Exception('RDB versions below doesn\'t support write-hooks')
14521459

14531460
table_type = None
14541461
if ext == ".json":

0 commit comments

Comments
 (0)