bug: `delete_user` returns `Exception` event if response is Ok
songololo opened this issue · 6 comments
The delete_user
method in api.py
raises an Exception at line 558
It does so even though the response from the http client (previous line) returns status 200.
@songololo What is the type of exception? Exception
exactly?
Can you show us a snippet code that raises this error and the content of the response?
Here is a minimal working example:
from gotrue import User
User.parse_obj({})
In the original context, the response from delete user returns an OK response with status 200
, but which is otherwise empty. This empty response is passed to parse_response
in api.py line 558, which, in turn, passes the empty dict
to parse_obj
in types.py line 29
i.e. the error can be mocked from one level higher per:
from gotrue import User
class MockResponse:
@classmethod
def raise_for_status(cls):
return None
@classmethod
def json(cls):
return {}
User.parse_response(MockResponse)
EDIT: fixed typos
Here is a minimal working example:
from gotrue import User User.parse_obj({})In the original context, the response from delete user returns an OK response with status 200, but which is otherwise empty. This empty response is passed to
cls.parse_obj
in api.py line 558, which, in turn, passes the emptydict
to types.py line 29i.e.
from gotrue import User class MockResponse: @classmethod def raise_for_status(cls): return None @classmethod def json(cls): return {} User.parse_response(MockResponse)
Thanks, we will review and fix it as soon as possible. We will also add a test to cover that method. Greetings.
Likewise, if you want to work on the fix because you need it urgently, do so. If not, no problem, we will fix it as soon as possible.
Thanks. For now I've simply modified my local copy to:
class BaseModelFromResponse(BaseModel):
@classmethod
def parse_response(cls: Type[T], response: Response) -> T:
check_response(response)
response_json = response.json()
if response_json == {}:
return
return cls.parse_obj(response_json)
But, I'm not sure how this affects the remainder of the system so I'll hold off suggesting concrete changes for now!