dj-stripe / dj-stripe

dj-stripe automatically syncs your Stripe Data to your local database as pre-implemented Django Models allowing you to use the Django ORM, in your code, to work with the data making it easier and faster.
https://dj-stripe.dev
MIT License
1.56k stars 474 forks source link

When installing for the first time and running migrate: AttributeError: module 'stripe' has no attribute 'Order' #2039

Closed dunctk closed 47 minutes ago

dunctk commented 1 month ago

Describe the bug When trying to install dj-stripe, running migrate causes the following error:

python manage.py migrate
Loading environment variables for .env file
Traceback (most recent call last):
  File "/media/dunc/data/Code/contentmarketingexamples/manage.py", line 34, in <module>
    main()
  File "/media/dunc/data/Code/contentmarketingexamples/manage.py", line 30, in main
    execute_from_command_line(sys.argv)
  File "/media/dunc/data/Code/contentmarketingexamples/venv/lib/python3.11/site-packages/django/core/management/__init__.py", line 442, in execute_from_command_line
    utility.execute()
  File "/media/dunc/data/Code/contentmarketingexamples/venv/lib/python3.11/site-packages/django/core/management/__init__.py", line 416, in execute
    django.setup()
  File "/media/dunc/data/Code/contentmarketingexamples/venv/lib/python3.11/site-packages/django/__init__.py", line 24, in setup
    apps.populate(settings.INSTALLED_APPS)
  File "/media/dunc/data/Code/contentmarketingexamples/venv/lib/python3.11/site-packages/django/apps/registry.py", line 116, in populate
    app_config.import_models()
  File "/media/dunc/data/Code/contentmarketingexamples/venv/lib/python3.11/site-packages/django/apps/config.py", line 269, in import_models
    self.models_module = import_module(models_module_name)
                         ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/lib/python3.11/importlib/__init__.py", line 126, in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "<frozen importlib._bootstrap>", line 1204, in _gcd_import
  File "<frozen importlib._bootstrap>", line 1176, in _find_and_load
  File "<frozen importlib._bootstrap>", line 1147, in _find_and_load_unlocked
  File "<frozen importlib._bootstrap>", line 690, in _load_unlocked
  File "<frozen importlib._bootstrap_external>", line 940, in exec_module
  File "<frozen importlib._bootstrap>", line 241, in _call_with_frames_removed
  File "/media/dunc/data/Code/contentmarketingexamples/venv/lib/python3.11/site-packages/djstripe/models/__init__.py", line 45, in <module>
    from .orders import Order
  File "/media/dunc/data/Code/contentmarketingexamples/venv/lib/python3.11/site-packages/djstripe/models/orders.py", line 15, in <module>
    class Order(StripeModel):
  File "/media/dunc/data/Code/contentmarketingexamples/venv/lib/python3.11/site-packages/djstripe/models/orders.py", line 24, in Order
    stripe_class = stripe.Order
                   ^^^^^^^^^^^^
  File "/media/dunc/data/Code/contentmarketingexamples/venv/lib/python3.11/site-packages/stripe/__init__.py", line 199, in __getattr__
    raise AttributeError(
AttributeError: module 'stripe' has no attribute 'Order'

To Reproduce run python manage.py migrate

Software versions

pmdevita commented 3 weeks ago

Stripe SDK is probably too new https://github.com/dj-stripe/dj-stripe/issues/1842

On a related note, is there a plan in place to deprecate Order and update the SDK?

jleclanche commented 3 weeks ago

@pmdevita yes this will be fixed in djstripe 2.9. I've decided to release an additional intermediate release before 3.0...

agusmakmun commented 3 weeks ago

Hello @dunctk, yes, it's stripe SDK, and already discussed here https://github.com/dj-stripe/dj-stripe/issues/1842#issuecomment-1319185657

I'm facing the same issue, and solved by installing this version:

stripe>=4.0.0,<5.0.0
jleclanche commented 47 minutes ago

This is fixed in 2.9.0a1 which was released recently, please test that release (note: it has not been tested in production yet, please create issues with all feedback).