Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
jceresini opened this issue Jan 4, 2018 · 1 comment
Closed

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

jceresini opened this issue Jan 4, 2018 · 1 comment
Assignees
Labels
api: logging Issues related to the Cloud Logging API. priority: p1 Important issue which blocks shipping the next release. Will be fixed prior to next release. type: bug Error or flaw in code with unintended results or allowing sub-optimal usage patterns.

Comments

@jceresini
Copy link

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'
@tseaver tseaver added api: logging Issues related to the Cloud Logging API. priority: p1 Important issue which blocks shipping the next release. Will be fixed prior to next release. type: bug Error or flaw in code with unintended results or allowing sub-optimal usage patterns. labels Jan 4, 2018
@tseaver tseaver self-assigned this Jan 4, 2018
@tseaver
Copy link
Contributor

tseaver commented Jan 4, 2018

@jceresini Thanks for the report! I think maybe the filter argument used to be required on the back-end, and so we never saw this case.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
api: logging Issues related to the Cloud Logging API. priority: p1 Important issue which blocks shipping the next release. Will be fixed prior to next release. type: bug Error or flaw in code with unintended results or allowing sub-optimal usage patterns.
Projects
None yet
Development

No branches or pull requests

2 participants