GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — fix: raise a ValueError in BucketNotification.create() if a topic name is not set by cojenco · Pull Request #617 · googleapis/python-storage

This repository was archived by the owner on Mar 31, 2026. It is now read-only.

Conversation

@cojenco

@cojenco cojenco commented Oct 6, 2021

Copy link
Copy Markdown
Contributor

A PubSub topic (topic name) is required to insert a BucketNotification according to the JSON API.

Raise a ValueError in BucketNotification.create() if topic_name = None. This adds a guard check and further prevents requests with invalid NoneType string interpolation.

Add tests and revise conformance tests.

Fixes #616 🦕

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
cojenco added 2 commits October 6, 2021 11:57
@cojenco
fix: topic name is required to create a notification. add check and t…
ed57668
…ests
@cojenco
revise conf tests
2103d1b
@product-auto-label product-auto-label Bot added the api: storage Issues related to the googleapis/python-storage API. label Oct 6, 2021
@google-cla google-cla Bot added the cla: yes This human has signed the Contributor License Agreement. label Oct 6, 2021
@cojenco cojenco changed the title Fix: raise a ValueError in BucketNotification.create() if a topic name is not set fix: raise a ValueError in BucketNotification.create() if a topic name is not set Oct 6, 2021
@cojenco
cojenco marked this pull request as ready for review October 6, 2021 20:21
@cojenco
cojenco requested review from a team October 6, 2021 20:21
unforced
unforced approved these changes Oct 6, 2021
View reviewed changes
tritone
tritone reviewed Oct 6, 2021
View reviewed changes
Comment thread google/cloud/storage/notification.py Outdated
"Notification already exists w/ id: {}".format(self.notification_id)
)

if self.topic_name is None:

@tritone tritone Oct 6, 2021

Copy link
Copy Markdown
Contributor

There was a problem hiding this comment.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What is the error from the service currently if the topic name is not included?

This might be fine, but in general we want to avoid overdoing it on client-side validation unless we have a good reason-- we want to let the service itself own most of this.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions

@cojenco cojenco Oct 7, 2021

Copy link
Copy Markdown
Contributor Author

There was a problem hiding this comment.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There's two parts to answer your question.

If the topic is not included, the server returns a 400 with error message "Invalid Google Cloud Pub/Sub topic. It should look like '//pubsub.googleapis.com/projects/*/topics/*.'"

In our client, on line 270, we preprocess the request body topic through string interpolation. So topic becomes "//pubsub.googleapis.com/projects/<project-identifier>/topics/None" if topic_name=None. Thus we get a 400 for another reason "Cloud Pub/Sub topic '//pubsub.googleapis.com/projects/project/topics/None' not found, ..."

To avoid overdoing client-side validation, I could instead change the logic around preparing/formatting the topic.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions

@tritone tritone Oct 11, 2021

Copy link
Copy Markdown
Contributor

There was a problem hiding this comment.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah okay-- yeah I think in this case since we are constructing the topic client-side using topic_name, that's a good reason to just do the validation ourselves. It would be confusing if users thought that they had to supply the whole path in the error message you show as topic_name. Let's just try to make as clear a message as possible for this.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions

@cojenco cojenco Oct 11, 2021

Copy link
Copy Markdown
Contributor Author

There was a problem hiding this comment.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've fixed the logic in constructing the topic. I like the idea of letting the service itself own the validation and aligning with the JSON API. Now the error from the server, if any, will bubble up directly. Will be merging the latest changes if no further questions. Thanks for the review @tritone!

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
@cojenco cojenco added the do not merge Indicates a pull request not ready for merge, due to either quality or timing. label Oct 7, 2021
cojenco added 5 commits October 7, 2021 14:56
@cojenco
fix topic formatting and remove extra validation
8842b13
@cojenco
blacken lint
02110e1
@cojenco
Merge branch 'main' into topic_name
227ee01
@cojenco
update docstrings
c7244a2
@cojenco
Merge branch 'main' into topic_name
b641a98
@cojenco cojenco removed the do not merge Indicates a pull request not ready for merge, due to either quality or timing. label Oct 11, 2021
@cojenco
cojenco merged commit 9dd78df into googleapis:main Oct 11, 2021
cojenco added a commit to cojenco/python-storage that referenced this pull request Oct 13, 2021
@cojenco
fix: raise a ValueError in BucketNotification.create() if a topic nam…
38ab5ac
…e is not set (googleapis#617)

* fix: topic name is required to create a notification. add check and tests

* revise conf tests

* fix topic formatting and remove extra validation

* blacken lint

* update docstrings
cojenco added a commit to cojenco/python-storage that referenced this pull request Oct 13, 2021
@cojenco
fix: raise a ValueError in BucketNotification.create() if a topic nam…
4a11b80
…e is not set (googleapis#617)

* fix: topic name is required to create a notification. add check and tests

* revise conf tests

* fix topic formatting and remove extra validation

* blacken lint

* update docstrings
gcf-merge-on-green Bot pushed a commit that referenced this pull request Nov 17, 2021
@release-please
chore: release 1.43.0 (#618)
979178b
🤖 I have created a release \*beep\* \*boop\*
---
## [1.43.0](https://www.github.com/googleapis/python-storage/compare/v1.42.3...v1.43.0) (2021-11-15)


### Features

* add ignore_flush parameter to BlobWriter ([#644](https://www.github.com/googleapis/python-storage/issues/644)) ([af9c9dc](https://www.github.com/googleapis/python-storage/commit/af9c9dc83d8582167b74105167af17c9809455de))
* add support for Python 3.10 ([#615](https://www.github.com/googleapis/python-storage/issues/615)) ([f81a2d0](https://www.github.com/googleapis/python-storage/commit/f81a2d054616c1ca1734997a16a8f47f98ab346b))


### Bug Fixes

* raise a ValueError in BucketNotification.create() if a topic name is not set ([#617](https://www.github.com/googleapis/python-storage/issues/617)) ([9dd78df](https://www.github.com/googleapis/python-storage/commit/9dd78df444d21af51af7858e8958b505a26c0b79))


### Documentation

* add contributing and authoring guides under samples/ ([#633](https://www.github.com/googleapis/python-storage/issues/633)) ([420591a](https://www.github.com/googleapis/python-storage/commit/420591a2b71f823dbe80f4a4405d8a514f87e0fb))
* add links to samples and how to guides ([#641](https://www.github.com/googleapis/python-storage/issues/641)) ([49f78b0](https://www.github.com/googleapis/python-storage/commit/49f78b09fed6d9f486639fd0a72542c30a0df084))
* add README to samples subdirectory ([#639](https://www.github.com/googleapis/python-storage/issues/639)) ([58af882](https://www.github.com/googleapis/python-storage/commit/58af882c047c31f59486513c568737082bca6350))
* update samples readme with cli args ([#651](https://www.github.com/googleapis/python-storage/issues/651)) ([75dda81](https://www.github.com/googleapis/python-storage/commit/75dda810e808074d18dfe7915f1403ad01bf2f02))
---


This PR was generated with [Release Please](https://github.com/googleapis/release-please). See [documentation](https://github.com/googleapis/release-please#release-please).
@cojenco
cojenco deleted the topic_name branch December 3, 2021 23:47
@release-please release-please Bot mentioned this pull request Jan 12, 2022
chore(main): release 3.0.0 #688
Closed
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Reviewers

2 more reviewers
@tritone tritone tritone left review comments
@unforced unforced unforced approved these changes
Reviewers whose approvals may not affect merge requirements

Uh oh!

There was an error while loading. Please reload this page.

Assignees

No one assigned

Labels

api: storage Issues related to the googleapis/python-storage API. cla: yes This human has signed the Contributor License Agreement.

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

BucketNotification.create() does not check if a topic is provided

Uh oh!

There was an error while loading. Please reload this page.

3 participants

@cojenco @unforced @tritone
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
You are visitor 01402775 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.