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: Add support to Dataset for project_ids with org prefix. #8646

Closed
ryanreno opened this issue Jul 11, 2019 · 1 comment · Fixed by #8877
Closed

BigQuery: Add support to Dataset for project_ids with org prefix. #8646

ryanreno opened this issue Jul 11, 2019 · 1 comment · Fixed by #8877
Assignees
Labels
api: bigquery Issues related to the BigQuery API. type: feature request ‘Nice-to-have’ improvement, new feature or different behavior or design.

Comments

@ryanreno
Copy link

Similar to #7827. Can not create a Dataset using a project ID with org prefix.

Environment details

  1. Python version: Python 3.6.5
  2. google-cloud- version:
    Name: google-cloud-bigquery
    Version: 1.16.0

Steps to reproduce

  1. Follow the Creating a Dataset guide

Code example

from google.cloud import bigquery

client = bigquery.Client()

dataset_id = f"{client.project}.ryan_dataset".

# Construct a full Dataset object to send to the API.
dataset = bigquery.Dataset(dataset_id)

Stack trace

---------------------------------------------------------------------------
ValueError                                Traceback (most recent call last)
<ipython-input-14-bfe46d108801> in <module>
----> 1 dataset = bigquery.Dataset(dataset_id)

~/.virtualenvs/bigquery/lib/python3.6/site-packages/google/cloud/bigquery/dataset.py in __init__(self, dataset_ref)
    368     def __init__(self, dataset_ref):
    369         if isinstance(dataset_ref, six.string_types):
--> 370             dataset_ref = DatasetReference.from_string(dataset_ref)
    371         self._properties = {"datasetReference": dataset_ref.to_api_repr(), "labels": {}}
    372 

~/.virtualenvs/bigquery/lib/python3.6/site-packages/google/cloud/bigquery/dataset.py in from_string(cls, dataset_id, default_project)
    305                 "Too many parts in dataset_id. Expected a fully-qualified "
    306                 "dataset ID in standard SQL format. e.g. "
--> 307                 '"project.dataset_id", got {}'.format(dataset_id)
    308             )
    309 

ValueError: Too many parts in dataset_id. Expected a fully-qualified dataset ID in standard SQL format. e.g. "project.dataset_id", got google.com:[project].ryan_dataset

I removed the project name from the stack trace.

@tseaver tseaver changed the title Bigquery Dataset does not support a project_id with org prefix Bigquery: add support to Dataset for project_ids with org prefix. Jul 11, 2019
@tseaver tseaver changed the title Bigquery: add support to Dataset for project_ids with org prefix. Bigquery: Add support to Dataset for project_ids with org prefix. Jul 11, 2019
@tseaver tseaver changed the title Bigquery: Add support to Dataset for project_ids with org prefix. BigQuery: Add support to Dataset for project_ids with org prefix. Jul 11, 2019
@tseaver tseaver added api: bigquery Issues related to the BigQuery API. type: feature request ‘Nice-to-have’ improvement, new feature or different behavior or design. labels Jul 11, 2019
@ryanreno
Copy link
Author

ryanreno commented Jul 11, 2019

A workaround I found:

from google.cloud import bigquery

client = bigquery.Client()

dataset_id = 'ryan_dataset'
dataset_ref = bigquery.DatasetReference.from_string(dataset_id, default_project=client.project)

dataset = bigquery.Dataset(dataset_ref)
dataset.location = 'US'
dataset = client.create_dataset(dataset)

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: feature request ‘Nice-to-have’ improvement, new feature or different behavior or design.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants