@@ -1667,8 +1667,30 @@ def __init__(self, connection, timeout):
1667
1667
self .connection = connection
1668
1668
self .timeout = timeout
1669
1669
1670
- def _handle_results (self , success , result ):
1671
- if success :
1670
+ def _handle_results (self , success , result , expected_failures = tuple ()):
1671
+ """
1672
+ Given a bool and a ResultSet (the form returned per result from
1673
+ Connection.wait_for_responses), return a dictionary containing the
1674
+ results. Used to process results from asynchronous queries to system
1675
+ tables.
1676
+
1677
+ ``expected_failures`` will usually be used to allow callers to ignore
1678
+ ``InvalidRequest`` errors caused by a missing system keyspace. For
1679
+ example, some DSE versions report a 4.X server version, but do not have
1680
+ virtual tables. Thus, running against 4.X servers, SchemaParserV4 uses
1681
+ expected_failures to make a best-effort attempt to read those
1682
+ keyspaces, but treat them as empty if they're not found.
1683
+
1684
+ :param success: A boolean representing whether or not the query
1685
+ succeeded
1686
+ :param result: The resultset in question.
1687
+ :expected_failures: An Exception class or an iterable thereof. If the
1688
+ query failed, but raised an instance of an expected failure class, this
1689
+ will ignore the failure and return an empty list.
1690
+ """
1691
+ if not success and isinstance (result , expected_failures ):
1692
+ return []
1693
+ elif success :
1672
1694
return dict_factory (* result .results ) if result else []
1673
1695
else :
1674
1696
raise result
@@ -1784,11 +1806,9 @@ def get_table(self, keyspaces, keyspace, table):
1784
1806
table_result = self ._handle_results (cf_success , cf_result )
1785
1807
col_result = self ._handle_results (col_success , col_result )
1786
1808
1787
- # handle the triggers table not existing in Cassandra 1.2
1788
- if not triggers_success and isinstance (triggers_result , InvalidRequest ):
1789
- triggers_result = []
1790
- else :
1791
- triggers_result = self ._handle_results (triggers_success , triggers_result )
1809
+ # the triggers table doesn't exist in C* 1.2
1810
+ triggers_result = self ._handle_results (triggers_success , triggers_result ,
1811
+ expected_failures = InvalidRequest )
1792
1812
1793
1813
if table_result :
1794
1814
return self ._build_table_metadata (table_result [0 ], col_result , triggers_result )
@@ -2533,24 +2553,18 @@ def _query_all(self):
2533
2553
# V4-only results
2534
2554
# These tables don't exist in some DSE versions reporting 4.X so we can
2535
2555
# ignore them if we got an error
2536
- if isinstance (virtual_ks_result , InvalidRequest ):
2537
- self .virtual_keyspaces_result = []
2538
- else :
2539
- self .virtual_keyspaces_result = self ._handle_results (
2540
- virtual_ks_success , virtual_ks_result
2541
- )
2542
- if isinstance (virtual_table_result , InvalidRequest ):
2543
- self .virtual_tables_result = []
2544
- else :
2545
- self .virtual_tables_result = self ._handle_results (
2546
- virtual_table_success , virtual_table_result
2547
- )
2548
- if isinstance (virtual_column_result , InvalidRequest ):
2549
- self .virtual_columns_result = []
2550
- else :
2551
- self .virtual_columns_result = self ._handle_results (
2552
- virtual_column_success , virtual_column_result
2553
- )
2556
+ self .virtual_keyspaces_result = self ._handle_results (
2557
+ virtual_ks_success , virtual_ks_result ,
2558
+ expected_failures = InvalidRequest
2559
+ )
2560
+ self .virtual_tables_result = self ._handle_results (
2561
+ virtual_table_success , virtual_table_result ,
2562
+ expected_failures = InvalidRequest
2563
+ )
2564
+ self .virtual_columns_result = self ._handle_results (
2565
+ virtual_column_success , virtual_column_result ,
2566
+ expected_failures = InvalidRequest
2567
+ )
2554
2568
2555
2569
self ._aggregate_results ()
2556
2570
0 commit comments