Repository navigation
fix(pubsub): accept messages without data - #322
Open
IzaakGough wants to merge 4 commits into
Open
IzaakGough wants to merge 4 commits into
IzaakGough wants to merge 4 commits into
Conversation
Contributor
There was a problem hiding this comment.
Code Review
This pull request updates the Message class in pubsub_fn.py to change the type of publish_time to a timezone-aware datetime and allows data to be None when a Pub/Sub message is published without a payload. It also updates the message handler to default data to None and adds comprehensive unit tests to verify these behaviors. I have no feedback to provide as there are no review comments.
IzaakGough
marked this pull request as ready for review
October 22, 2026 13:47
CorieW
approved these changes
Oct 22, 2026
CorieW
left a comment
Member
There was a problem hiding this comment.
LGTM
nits:
data=""still makes.jsonraise, whiledata=NonereturnsNone. Should""returnNonetoo, in case the emulator sends attribute-only messages that way?data: str | Nonemay cause new mypy/pyright warnings for users (e.g.b64decode(msg.data)). Worth a changelog note?- No test covers a present
orderingKey(e.g."abc"→ordering_key == "abc"). - The older tests could reuse
_raw_eventinstead of building the CloudEvent by hand.
The emulator sends data as an empty string for attribute-only messages. Also cover a present ordering key and reuse _raw_event in older tests.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
A Pub/Sub message that has attributes but no data crashed
on_message_publishedwithTypeError: Message.__init__() missing 1 required positional argument: 'data'before the handler ran.This lets those messages through with
dataset toNone, makesNonethe default fordatawhen building aMessagedirectly, and typespublish_timeas thedatetimeit already is.ordering_keyis nowstr | None = None. The field afterdataneeds a default too, and the handler already passedNonewhen there is no ordering key.datais now typedstr | None, so type checkers will flag code that passesmsg.datastraight tob64decode..jsonreturnsNonefor both a missing and an empty payload, because the emulator sends""for attribute-only messages.datetimeimport this annotation uses. Whichever PR lands second should keep it.Tested with unit tests and in the emulator with an attribute-only message. Not tested with a real Pub/Sub delivery.