-
Notifications
You must be signed in to change notification settings - Fork 43
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
APIRequest Handler misbehaviour #134
Comments
I would add that @Changaco already made a remark in #96 but you didn't really pay attention I think
|
Hello @BboyKeen, Thanks for your remarks about our SDK. Mickaël |
I second this. The handler doesn’t make any sense:
So (as far as I can tell), the only way to set the |
@joecridge You should try to use the snippet in my comment to override the handler. This way, you'll be able to set proxies, timeout and so on. |
@BboyKeen yeah I’ve used that as a workaround, thanks. Ideally, though, it would be nice if the documentation was updated to match the implementation, or vice versa. |
Just a note to add that the above snippets don’t work on their own, because the handler always falls back to the # From the mangopay.api module:
class APIRequest(object):
def __init__(self, ... , sandbox=None, ... ):
if sandbox or mangopay.sandbox: # <--- !!!
self.api_url = api_sandbox_url or mangopay.api_sandbox_url
else:
self.api_url = api_url or mangopay.api_url Since So to use the production environment and specify any other handler settings, you need to do something like this: import mangopay
# Set sandbox.
mangopay.sandbox = False
# Set your other settings.
_handler = mangopay.APIRequest(<settings excluding sandbox>)
def get_default_handler():
return _handler
# Monkeypatch `get_default_handler` everywhere.
mangopay.get_default_handler = get_default_handler
mangopay.base.get_default_handler = get_default_handler
mangopay.query.get_default_handler = get_default_handler This is just a combination of @BboyKeen’s code from above and @chocopoche’s code from #96, but hopefully seeing them in combination might be of help to the next person who stumbles upon this issue. 🙂 |
Changes added in latest release |
Hi Mangopay folks,
After scratching my head a few hours digging in your code, I came to the conclusion that the way you implemented the APIRequest handler is not working.
It looks like your implementation completely ignores custom APIRequest like the one below (implementation get from the documentation) because it relies internally on the get_default_handler() method only.
This small POC below enlights this fact by showing the references of the registered handler.
As you can see after executing it, it will output something like that :
By looking at the references of the objects, we can easily understand that the resource is using the memoized handler and not the custom one.
As a consequence, defining things like sandbox, timeout, proxies, storage_strategy or anything in the APIRequest is useless if the custom handler doesn't override the default one.
The text was updated successfully, but these errors were encountered: