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

cannot import name 'ApiContext' from 'bunq.sdk.context' #132

Closed
echoes341 opened this issue Apr 16, 2020 · 5 comments · Fixed by #143
Closed

cannot import name 'ApiContext' from 'bunq.sdk.context' #132

echoes341 opened this issue Apr 16, 2020 · 5 comments · Fixed by #143

Comments

@echoes341
Copy link

echoes341 commented Apr 16, 2020

I cannot import ApiContext. I'm not expert on Python, so there's no much I can do to help unfortunately.

Steps to reproduce:

This is easy to reproduce with docker

$ docker run --rm -it python bash

On the interactive shell:

root@2b615a0e8b39:/# pip install bunq_sdk
...
root@2b615a0e8b39:/# mkdir test
root@2b615a0e8b39:/# cd test
root@2b615a0e8b39:/test# cat > test.py
from bunq.sdk.context import ApiContext
print('Hello')
root@2b615a0e8b39:/test# python test.py
Traceback (most recent call last):
  File "test.py", line 1, in <module>
    from bunq.sdk.context import ApiContext
ImportError: cannot import name 'ApiContext' from 'bunq.sdk.context' (/usr/local/lib/python3.8/
site-packages/bunq/sdk/context/__init__.py)

What should happen:

  1. It should import the module

What happens:

  1. It fails returning:
ImportError: cannot import name 'ApiContext' from 'bunq.sdk.context' (/usr/local/lib/python3.8/
site-packages/bunq/sdk/context/__init__.py)

SDK version and environment

  • Tested on 1.13.1

Response id

  • Response id:

Extra info:

@MarcellaJP
Copy link

We had the same issue after upgrading to the latest version and it's because there are several breaking changes in the new version... Change the import to:

from bunq.sdk.context.bunq_context import ApiContext

In case it might help, other breaking changes that I have encountered are:

  • from bunq.sdk.client import Pagination should now be from bunq import Pagination
  • from bunq.sdk.context import BunqContext should now be from bunq.sdk.context.bunq_context import BunqContext
  • from bunq.sdk.context import ApiContext should now be from bunq.sdk.context.bunq_context import ApiContext
  • from bunq.sdk.context import ApiEnvironmentType should now be from bunq.sdk.context.api_environment_type import ApiEnvironmentType

And whereas before you could initialize the ApiContext with something as

  • api_context = ApiContext(ENVIRONMENT_TYPE, API_KEY, DEVICE_DESCRIPTION)
    It should now be:
  • api_context = ApiContext.create(ENVIRONMENT_TYPE, API_KEY, DEVICE_DESCRIPTION)

Good luck!

@echoes341
Copy link
Author

Thank you @MarcellaJP !

@tlrh314
Copy link

tlrh314 commented Aug 8, 2020

The changelog is restored in 9d7dbc9, indicating that major refactoring was merged in #117.

@angelomelonas It would be neat if a word of caution would be added to the README and in the description of the 1.13.1 release itself that updating from 1.10.16 to 1.13.1 requires users of this package to implement the fixes as indicated by @MarcellaJP.

@angelomelonas
Copy link
Contributor

angelomelonas commented Aug 11, 2020

Hi everyone. I apologise for the very late response to this issue.

In order to improve the readability and maintainability of the Python SDK, we performed this refactor. Instead of having functions in very large files, we extracted them into separate files (to match the directory and file structure of the other SDKs). In the process, we also added type hints and other general improvements.

Unfortunately, this leads to the breaking changes @echoes341 and @MarcellaJP mention above. We definitely should have mentioned them in the CHANGELOG.

We have created a new issue which mentions the breaking changes. We will create a new PR that mentions the breaking changes (and the issue) in the CHANGELOG.

@angelomelonas angelomelonas linked a pull request Aug 11, 2020 that will close this issue
@tlrh314
Copy link

tlrh314 commented Aug 11, 2020

Awesome, thanks @angelomelonas 🔥 🤩

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants