Skip to content

Commit

Permalink
Be compatible with HTTP 202 streaming response
Browse files Browse the repository at this point in the history
Metabase is introducing new mechanism to its API. 
It's called streaming API and it will enable to return HTTP 202 (instead of HTTP 200) code and a status token, which later can be used to check if particular async operation was a success, or threw an error. 
The issue where this initiative started: metabase/metabase#11726
Some sort of very short info in the docs: https://github.com/metabase/metabase/wiki/Metabase-REST-API-Patterns

The current situation in version v0.35.3 is such that API endpoints used by this python library return 202 code, but the same JSON body as before. Even for operations such as creation of new card, where I can see that some processing is done in the server, the return value is same as before.

This simple PR accepts http 202 as an OK return code. We're currently working with this library to create a metabase based ETL/analytics tool, and will be paying attention to further developments here.  Shall Metabase API introduce returning the `_status`  token, we'll implement it.
  • Loading branch information
marcinkoziej authored May 26, 2020
1 parent fe7aa18 commit 328420c
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions metabase/metabase.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,13 +27,13 @@ def get_session_headers(self, *args, **kwargs):
return self.session_header()

def fetch_header(self, r):
if r.status_code == 200:
if r.status_code == 200 or r.status_code == 202:
return True
else:
return False

def fetch_body(self, r):
if r.status_code == 200:
if r.status_code == 200 or r.status_code == 202:
return True, r.json()
else:
return False, None
Expand Down

0 comments on commit 328420c

Please sign in to comment.