GeezerVisonThe World Wide Web, restored to 800 pixels of glory. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Home|About|Gaming cabinet|Archives|How it works|Starter sites | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
GeezerVison is showing github.com — docs: add sample for revoking dataset access by loferris · Pull Request #778 · googleapis/python-bigquery
This repository was archived by the owner on Mar 6, 2026. It is now read-only.
Conversation
Contributor
Thank you for opening a Pull Request! Before submitting your PR, there are a few things you can do to make sure it goes smoothly:
Sorry, something went wrong. Uh oh!
There was an error while loading. Please reload this page. All reactions
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
There was an error while loading. Please reload this page.
|
Here is the summary of changes. You are about to add 4 region tags.
This comment is generated by snippet-bot.
|
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
Found a few things that could probably be improved, although nothing really major.
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
| client = bigquery.Client() | ||
|
|
||
| # TODO(developer): Set dataset_id to the ID of the dataset to fetch. | ||
| # dataset_id = 'your-project.your_dataset' |
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
I've gotten docs feedback from users skip over this comments and get confused. Could we instead follow this pattern where we set a real value and then immediately unset it?
I didn't add the TODO comment in that BQ Storage sample, but I do like that you have it.
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
done
Sorry, something went wrong.
There was an error while loading. Please reload this page.
| entries = list(dataset.access_entries) | ||
|
|
||
| for entry in entries: | ||
| if entry.entity_id == entity_id: |
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
You use entity_id without showing an example value. Each code sample should be as copy-pasteable as possible. Add the setter for this by the setter for dataset_id.
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
done
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
…ython-bigquery into bigquery_remove_view_access merging in changes from remote branch
…hange parameter pattern for readibility
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
Looks good, thanks for making the changes.
I'll let Tim comment on START/END section naming (in case there are some implicit conventions), although the changes look consistent with the linked pattern to me.
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
Whoops, it appears we need to add __init__.py to samples/snippets, it's currently not present:
/usr/local/lib/python3.6/importlib/__init__.py:126: in import_module
return _bootstrap._gcd_import(name[level:], package, level)
revoke_dataset_access_test.py:15: in <module>
from .. import update_dataset_access
E ImportError: attempted relative import with no known parent package
We'll also need to adjust the imports in the test, because both files are now in the same directory. The following will fail now:
from .. import revoke_dataset_access
Sorry, something went wrong.
There was an error while loading. Please reload this page.
If we do add it, then we'll need to change all the other tests to in |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
Indeed. It's a bit more (one-time) work, but it will make the |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
| # See the License for the specific language governing permissions and | ||
| # limitations under the License. | ||
|
|
||
| from .. import update_dataset_access |
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
As mentioned in the comment, adding samples/snippets/__init__.py should fix this, but it'll break the other sample tests. You'll need to also update the tests in samples/snippets/ to use relative imports.
Alternatively, we can start making progress on migrating the snippets to samples/snippets (#790). You could make a copy of update_dataset_access.py and it's corresponding tests and put them in the samples/snippets directory in this PR. Then once you've pointed cloud.google.com at the new sample location, send a PR to remove the duplicate sample.
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
I like the latter approach!
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
done in latest commit!
Sorry, something went wrong.
There was an error while loading. Please reload this page.
| # limitations under the License. | ||
|
|
||
| from .. import update_dataset_access | ||
| from .. import revoke_dataset_access |
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
This should be from . import revoke_dataset_access since it's the same directory as the test. (Also will need __init__.py for that to work.) If you go with the "copy" alternative (without __init__.py), then this should be import revoke_dataset_access.
Sorry, something went wrong.
There was an error while loading. Please reload this page.
| revoke_dataset_access.revoke_dataset_access(dataset_id, entity_id) | ||
|
|
||
| out, err = capsys.readouterr() | ||
| assert f"Updated dataset '{dataset_id}' with modified user permissions." in out |
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
Could you look for a message specific to "revoke"? I worry that this could catch the original update and the revoke could be failing.
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
Also, let's add some additional steps to call get_dataset and check that the dataset access was actually updated.
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
would you recommend the pytest fixture pattern to create a bigquery client that I can call this on? I'm seeing it in some other snippets but not the update_access sample. I also need to move get_dataset to /snippets as well!
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
| entries = list(dataset.access_entries) | ||
|
|
||
| for entry in entries: | ||
| if entry.entity_id == entity_id: |
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
Do you think we should we look at entity_type, too? Maybe not? I suppose there shouldn't be much conflict between whether an email address is associated with a group, service account, or user.
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
once I get the tests updated I'll play around with it.
Sorry, something went wrong.
There was an error while loading. Please reload this page.
| dataset = client.update_dataset(dataset, ["access_entries"]) # Make an API request. | ||
|
|
||
| full_dataset_id = f"{dataset.project}.{dataset.dataset_id}" | ||
| print(f"Updated dataset '{full_dataset_id}' with modified user permissions.") |
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
Including the word "revoked" and possibly the entity ID here could give us a better idea that this actually worked.
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
|
|
||
| for entry in entries: | ||
| if entry.entity_id == entity_id: | ||
| entry.role = None |
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
I'm curious to see if this works as expected. The alternative is to remove the whole entry from the list.
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
I'm going to remove it...
Sorry, something went wrong.
There was an error while loading. Please reload this page.
…ke_access and update_access
removed nested START/END tags Co-authored-by: Tim Swast <[email protected]>
update readability in API request Co-authored-by: Tim Swast <[email protected]>
|
Hi @tswast This is ready for a final/next review! |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
| ) | ||
|
|
||
| entries = list(dataset.access_entries) | ||
| entries.append(entry) |
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
I'm a bit confused as to why we'd add the entry and then remove it on line 42. Perhaps a copy-paste error?
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
I think it's a redundancy - I was adding a specific entry to alter but I think that'll be covered in the test case and sort of muddies the water in the sample itself. I'll refactor.
Sorry, something went wrong.
There was an error while loading. Please reload this page.
| entry = bigquery.AccessEntry( | ||
| role="READER", | ||
| entity_type="groupByEmail", | ||
| entity_id="[email protected]", |
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
Should this be entity_id=entity_id?
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
Makes sense to me!
Sorry, something went wrong.
There was an error while loading. Please reload this page.
|
|
||
| entry = bigquery.AccessEntry( | ||
| role="READER", | ||
| entity_type="groupByEmail", |
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
We should add a comment saying that the developer will need to set this to the correct type.
Although, perhaps we can delete this whole line 32-36? A code sample should only contain the logic necessary for the developer to understand the concept we're trying to teach them.
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
I took it out!
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
| entry = bigquery.AccessEntry( | ||
| role="READER", | ||
| entity_type="groupByEmail", | ||
| entity_id="[email protected]", |
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
Do we want to use the entity_id fixture here? If so, we should add a variable above.
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
Added, changed test as well!
Sorry, something went wrong.
There was an error while loading. Please reload this page.
|
|
||
| entry = bigquery.AccessEntry( | ||
| role="READER", | ||
| entity_type="groupByEmail", |
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
This needs a comment explaining the various options available, or at least a link to the docs where these are described.
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
Added!
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
| @@ -0,0 +1,49 @@ | |||
| # Copyright 2021 Google LLC | |||
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
Nit: In the filename, "access" and "permissions" are redundant. Let's call it dataset_access_test.py.
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
Done in latest commit!
Sorry, something went wrong.
There was an error while loading. Please reload this page.
| https://cloud.google.com/python/setup | ||
|
|
||
| #. Create a virtualenv. Samples are compatible with Python 3.6+. | ||
| #. Create a virtualenv. Samples are compatible with Python 2.7 and 3.4+. |
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
@loferris Please revert the changes to this file.
Sorry, something went wrong.
There was an error while loading. Please reload this page.
Co-authored-by: Tim Swast <[email protected]>
Co-authored-by: Tim Swast <[email protected]>
Co-authored-by: Tim Swast <[email protected]>
Co-authored-by: Tim Swast <[email protected]>
|
All comments addressed! @tswast |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
| client = bigquery.Client() | ||
|
|
||
| # TODO(developer): Set dataset_id to the ID of the dataset to fetch. | ||
| # dataset_id = 'your-project.your_dataset' |
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
Looks like we missed this one.
Sorry, something went wrong.
There was an error while loading. Please reload this page.
Co-authored-by: Tim Swast <[email protected]>
Co-authored-by: Tim Swast <[email protected]>
Co-authored-by: Tim Swast <[email protected]>
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
LGTM. I've pushed some minor updates to the comments.
Sorry, something went wrong.
There was an error while loading. Please reload this page.
| dataset = client.get_dataset(dataset_id) # Make an API request. | ||
|
|
||
| entries = list(dataset.access_entries) | ||
| dataset.access_entries = entries |
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
This line confuses me. It gets overwritten in the next line of code, so looks unnecessary. Possibly leftover from a debugging?
Sorry, something went wrong.
There was an error while loading. Please reload this page.
* revoke dataset access setup * basic template for sample * sample + test * revoke dataset access sample * 🦉 Updates from OwlBot See https://github.com/googleapis/repo-automation-bots/blob/master/packages/owl-bot/README.md * docs: add sample for revoking dataset access - update year and string formatting * docs: add sample for revoking dataset access - move to snippets and change parameter pattern for readibility * moving update_dataset to /snippets and adjusting imports on both revoke_access and update_access * Update samples/snippets/revoke_dataset_access.py removed nested START/END tags Co-authored-by: Tim Swast <[email protected]> * Update samples/snippets/revoke_dataset_access.py update readability in API request Co-authored-by: Tim Swast <[email protected]> * 🦉 Updates from OwlBot See https://github.com/googleapis/repo-automation-bots/blob/master/packages/owl-bot/README.md * updated test * 🦉 Updates from OwlBot See https://github.com/googleapis/repo-automation-bots/blob/master/packages/owl-bot/README.md * change after running test * resolving linting failure, rewriting test * removed relative import errors * remove relative mport from update_dataset_access * adding fixture to conftest.py * updated sample * updating sample to match new update_access sample * fixing region tags * consolidated tests into one file for both methods * updating test to full_dataset format * updated revoke sample * updating test * refactored sample * Update samples/snippets/conftest.py * Update samples/snippets/revoke_dataset_access.py Co-authored-by: Tim Swast <[email protected]> * Update samples/snippets/update_dataset_access.py Co-authored-by: Tim Swast <[email protected]> * Update samples/snippets/revoke_dataset_access.py Co-authored-by: Tim Swast <[email protected]> * Update samples/snippets/revoke_dataset_access.py Co-authored-by: Tim Swast <[email protected]> * refactoring entry * added comment for entry access * Update samples/snippets/README.rst Co-authored-by: Tim Swast <[email protected]> * Update samples/snippets/dataset_access_test.py Co-authored-by: Tim Swast <[email protected]> * Update samples/snippets/dataset_access_test.py Co-authored-by: Tim Swast <[email protected]> * added develper TODO in sample * add comments to samples Co-authored-by: Owl Bot <gcf-owl-bot[bot]@users.noreply.github.com> Co-authored-by: Tim Swast <[email protected]> Co-authored-by: Peter Lamut <[email protected]> Co-authored-by: Anthonios Partheniou <[email protected]> Co-authored-by: meredithslota <[email protected]>
There was an error while loading. Please reload this page.
Successfully merging this pull request may close these issues.
There was an error while loading. Please reload this page.