Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

BigQuery dataset.list_tables() fails when the dataset is empty #1419

Closed
evmin opened this issue Jan 26, 2016 · 8 comments
Closed

BigQuery dataset.list_tables() fails when the dataset is empty #1419

evmin opened this issue Jan 26, 2016 · 8 comments
Assignees
Labels
api: bigquery Issues related to the BigQuery API. type: bug Error or flaw in code with unintended results or allowing sub-optimal usage patterns.

Comments

@evmin
Copy link

evmin commented Jan 26, 2016

Good day.

Getting this exception when the BigQuery dataset contains no tables:

  File "/Library/Python/2.7/site-packages/gcloud/bigquery/dataset.py", line 507, in list_tables
    for resource in resp['tables']]
KeyError: 'tables'

Mac OS X El Capitan. gcloud 0.8.0

@dhermes dhermes added the api: bigquery Issues related to the BigQuery API. label Jan 26, 2016
@dhermes dhermes added the type: bug Error or flaw in code with unintended results or allowing sub-optimal usage patterns. label Jan 26, 2016
@dhermes
Copy link
Contributor

dhermes commented Jan 26, 2016

Thanks @evmin!

@dhermes dhermes assigned dhermes and unassigned tseaver Jan 26, 2016
@dhermes
Copy link
Contributor

dhermes commented Jan 26, 2016

I reproduced with

>>> from gcloud import bigquery
>>> client = bigquery.Client()
>>> dataset_name = 'foo_bar_baz'
>>> dataset = client.dataset(dataset_name)
>>> if dataset.exists():
...     raise ValueError('Expected a new dataset')
...
>>> dataset.create()
>>> dataset.exists()
True
>>> all_tables, token = dataset.list_tables()
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "gcloud/bigquery/dataset.py", line 553, in list_tables
    for resource in resp['tables']]
KeyError: 'tables'
>>> dataset.delete()
>>>

at 2323e1a

@tseaver
Copy link
Contributor

tseaver commented Jan 28, 2016

What is the content of resp at that point? The API docs don't indicate that the tables key is optional. We can defend against it, but shouldn't have to, IMHO.

@tseaver tseaver assigned tseaver and unassigned dhermes Jan 28, 2016
@dhermes
Copy link
Contributor

dhermes commented Jan 28, 2016

@tseaver I sent out a fix for this already.

@tseaver
Copy link
Contributor

tseaver commented Jan 28, 2016

Oops, my bad.

@dhermes
Copy link
Contributor

dhermes commented Jan 28, 2016

@tseaver Here is the full payload

{
  "etag": "\"AMpOK...\"", 
  "kind": "bigquery#tableList", 
  "totalItems": 0
}

Anything issue there before I merge the fix?

@tseaver
Copy link
Contributor

tseaver commented Jan 28, 2016

Nope, I was just "arguing with the ref": like it would have hurt the back-end to send the extra 13 bytes. :(

@dhermes
Copy link
Contributor

dhermes commented Jan 28, 2016

Gotcha.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
api: bigquery Issues related to the BigQuery API. type: bug Error or flaw in code with unintended results or allowing sub-optimal usage patterns.
Projects
None yet
Development

No branches or pull requests

3 participants