Skip to content

Logging: sink reload throws exception if the sink has no filter #4696

@jceresini

Description

@jceresini

A KeyError exception for 'filter' is thrown when calling [sink].reload() if there is no filter. The API doesn't return a 'filter' key when retrieving the sink if its null.

Python 3.5.2
google-cloud-core (0.28.0)
google-cloud-logging (1.4.0)

Simplified code example

logging_client = logging.Client(project_id)
sink = logging_client.sink(sink_name)
sink.reload()

Raw API response for sink request (via gcloud)

 $ gcloud logging sinks list --project xxxx --log-http 
 =======================
 ==== request start ====
 uri: https://logging.googleapis.com/v2/projects/xxxx/sinks?alt=json
 method: GET
 [...]
 -- body start --
 {
   "sinks": [
     {
       "name": "xxxx",
       "destination": "storage.googleapis.com/xxxx",
       "outputVersionFormat": "V2",
       "writerIdentity": "serviceAccount:xxxx"
     }
   ]
 }
 
 -- body end --
 
 [...]
 NAME       DESTINATION                  FILTER
 xxxx       storage.googleapis.com/xxxx  (empty filter)

Problematic code

/google/cloud/logging/sink.py Line 157
self.filter_ = data['filter']

Traceback

Traceback (most recent call last):
  File "/[...]/python3.5/site-packages/xxxx", line 50, in _get_sink
    sink.reload()
  File "[...]/python3.5/site-packages/google/cloud/logging/sink.py", line 157, in reload
    self.filter_ = data['filter']
KeyError: 'filter'

Metadata

Metadata

Assignees

Labels

api: loggingIssues related to the Cloud Logging API.priority: p1Important issue which blocks shipping the next release. Will be fixed prior to next release.type: bugError or flaw in code with unintended results or allowing sub-optimal usage patterns.

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions