googleapis / googleapis/google-cloud-ruby
PubSub: the data is wrongly merge into attributes when the publication's attributes is empty/nil
- Dominant language
- Ruby
- Stars
- 1.4k
- Forks
- 578
- Avg merge
- 1d 11h
- Merged PRs (30d)
- 166
Description
When there's no attributes or no extra attributes the data payload end up into the attributes when you are using a hash. This is habitually not an issue but when one of your values is really big it crash...
Ideally we should not merge attributes and data and always keep those separated.
Cause, as you can see at https://github.com/googleapis/google-cloud-ruby/blob/main/google-cloud-pubsub/lib/google/cloud/pubsub/convert.rb#L54
```ruby
def pubsub_message data, attributes, ordering_key, extra_attrs
if data.is_a?(::Hash) && (attributes.nil? || attributes.empty?)
attributes = data.merge extra_attrs
data = nil
else
attributes = Hash(attributes).merge extra_attrs
end
....
```
it should be more something like:
```ruby
def pubsub_message data, attributes, ordering_key, extra_attrs
attributes = Hash(attributes).merge extra_attrs
...
```
#### Environment details
- OS: ANY
- Ruby version: ANY
- Gem name and version: ANY
#### Code example
```ruby
google_pubsub_client ||= Google::Cloud::PubSub.new(
project_id:
)
initalized_topic = google_pubsub_client.topic()
initalized_topic.publish({a: , b: 3})
```
Thanks!
Contributor guide
Assessment
This issue has not been assessed yet.