Skip to content

Commit 8ccce60

Browse files
committed
_parse_table_name failed in the event of a name like <desc>_YYYYMMDD_<int>
1 parent 0edf54c commit 8ccce60

File tree

2 files changed

+14
-2
lines changed

2 files changed

+14
-2
lines changed

bigquery/client.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1436,6 +1436,8 @@ def _parse_table_name(self, table_id):
14361436
"""Parse a table name in the form of appid_YYYY_MM or
14371437
YYYY_MM_appid and return a tuple consisting of YYYY-MM and the app id.
14381438
1439+
Returns (None, None) in the event of a name like <desc>_YYYYMMDD_<int>
1440+
14391441
Parameters
14401442
----------
14411443
table_id : str
@@ -1463,9 +1465,10 @@ def _parse_table_name(self, table_id):
14631465
year_month = "-".join(attributes[-2:])
14641466
app_id = "-".join(attributes[:-2])
14651467

1468+
14661469
# Check if date parsed correctly
14671470
if year_month.count("-") == 1 and all(
1468-
[num.isdigit() for num in year_month.split('-')]):
1471+
[num.isdigit() for num in year_month.split('-')]) and len(year_month) == 7:
14691472
return year_month, app_id
14701473

14711474
return None, None

bigquery/tests/test_client.py

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1333,6 +1333,15 @@ def test_not_inside_range(self):
13331333
"kind": "bigquery#tableList",
13341334
"etag": "\"GSclnjk0zID1ucM3F-xYinOm1oE/cn58Rpu8v8pB4eoJQaiTe11lPQc\"",
13351335
"tables": [
1336+
{
1337+
"kind": "bigquery#table",
1338+
"id": "project:dataset.notanappspottable_20130515_0261",
1339+
"tableReference": {
1340+
"projectId": "project",
1341+
"datasetId": "dataset",
1342+
"tableId": "notanappspottable_20130515_0261"
1343+
}
1344+
},
13361345
{
13371346
"kind": "bigquery#table",
13381347
"id": "project:dataset.2013_05_appspot_1",
@@ -2389,7 +2398,7 @@ def test_get_all_tables(self):
23892398
bq = client.BigQueryClient(mock_bq_service, 'project')
23902399

23912400
expected_result = [
2392-
'2013_05_appspot', '2013_06_appspot_1', '2013_06_appspot_2',
2401+
'notanappspottable_20130515_0261', '2013_05_appspot', '2013_06_appspot_1', '2013_06_appspot_2',
23932402
'2013_06_appspot_3', '2013_06_appspot_4', '2013_06_appspot_5',
23942403
'appspot_6_2013_06', 'table_not_matching_naming'
23952404
]

0 commit comments

Comments
 (0)