From 8ccce603045a24bd0df49a2bf26a946ac84cba6e Mon Sep 17 00:00:00 2001 From: e271828- Date: Sat, 27 May 2017 09:27:37 -0700 Subject: [PATCH] _parse_table_name failed in the event of a name like _YYYYMMDD_ --- bigquery/client.py | 5 ++++- bigquery/tests/test_client.py | 11 ++++++++++- 2 files changed, 14 insertions(+), 2 deletions(-) diff --git a/bigquery/client.py b/bigquery/client.py index 17a3a89..b8971cd 100644 --- a/bigquery/client.py +++ b/bigquery/client.py @@ -1436,6 +1436,8 @@ def _parse_table_name(self, table_id): """Parse a table name in the form of appid_YYYY_MM or YYYY_MM_appid and return a tuple consisting of YYYY-MM and the app id. + Returns (None, None) in the event of a name like _YYYYMMDD_ + Parameters ---------- table_id : str @@ -1463,9 +1465,10 @@ def _parse_table_name(self, table_id): year_month = "-".join(attributes[-2:]) app_id = "-".join(attributes[:-2]) + # Check if date parsed correctly if year_month.count("-") == 1 and all( - [num.isdigit() for num in year_month.split('-')]): + [num.isdigit() for num in year_month.split('-')]) and len(year_month) == 7: return year_month, app_id return None, None diff --git a/bigquery/tests/test_client.py b/bigquery/tests/test_client.py index 1315147..a331387 100644 --- a/bigquery/tests/test_client.py +++ b/bigquery/tests/test_client.py @@ -1333,6 +1333,15 @@ def test_not_inside_range(self): "kind": "bigquery#tableList", "etag": "\"GSclnjk0zID1ucM3F-xYinOm1oE/cn58Rpu8v8pB4eoJQaiTe11lPQc\"", "tables": [ + { + "kind": "bigquery#table", + "id": "project:dataset.notanappspottable_20130515_0261", + "tableReference": { + "projectId": "project", + "datasetId": "dataset", + "tableId": "notanappspottable_20130515_0261" + } + }, { "kind": "bigquery#table", "id": "project:dataset.2013_05_appspot_1", @@ -2389,7 +2398,7 @@ def test_get_all_tables(self): bq = client.BigQueryClient(mock_bq_service, 'project') expected_result = [ - '2013_05_appspot', '2013_06_appspot_1', '2013_06_appspot_2', + 'notanappspottable_20130515_0261', '2013_05_appspot', '2013_06_appspot_1', '2013_06_appspot_2', '2013_06_appspot_3', '2013_06_appspot_4', '2013_06_appspot_5', 'appspot_6_2013_06', 'table_not_matching_naming' ]