Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
1.1k views
in Technique[技术] by (71.8m points)

pip - Python library `arrow` throws AttributeError: unknown attribute: "months"

I'm in process of upgrading an existing project. After upgrading arrow to 0.17.0, it starts throwing an exception when on attribute of months.

The issue goes away if downgrade arrow to 0.13.x; but I hope to upgrade to the latest version and fix the issue in the good way. Any input will be highly appreciated.

  ...
  File "/data/app/PROJECT/projectapp/rest/views.py", line 219, in get_precache_redeemable_codes
    create_ts__gte=arrow.now().replace(months=-1).datetime)) 
  File "/data/app/venv3.7/lib/python3.7/site-packages/arrow/arrow.py", line 807, in replace
    raise AttributeError('unknown attribute: "{}"'.format(key))
AttributeError: unknown attribute: "months"

In my application source code, the triggering function call is:

create_ts__gte=arrow.now().replace(months=-1).datetime)) 
  .select_related('customer') 
  .prefetch_related('orderitem_set')

The full trace of exception:

[27/Jan/2021 14:44:32] ERROR [django.request:230] Internal Server Error: /api/redeem/precache/
Traceback (most recent call last):
  File "/data/app/venv3.7/lib/python3.7/site-packages/django/core/handlers/exception.py", line 47, in inner
    response = get_response(request)
  File "/data/app/venv3.7/lib/python3.7/site-packages/django/core/handlers/base.py", line 179, in _get_response
    response = wrapped_callback(request, *callback_args, **callback_kwargs)
  File "/data/app/venv3.7/lib/python3.7/site-packages/django/views/decorators/csrf.py", line 54, in wrapped_view
    return view_func(*args, **kwargs)
  File "/data/app/venv3.7/lib/python3.7/site-packages/django/views/generic/base.py", line 70, in view
    return self.dispatch(request, *args, **kwargs)
  File "/data/app/venv3.7/lib/python3.7/site-packages/rest_framework/views.py", line 509, in dispatch
    response = self.handle_exception(exc)
  File "/data/app/venv3.7/lib/python3.7/site-packages/rest_framework/views.py", line 469, in handle_exception
    self.raise_uncaught_exception(exc)
  File "/data/app/venv3.7/lib/python3.7/site-packages/rest_framework/views.py", line 480, in raise_uncaught_exception
    raise exc
  File "/data/app/venv3.7/lib/python3.7/site-packages/rest_framework/views.py", line 506, in dispatch
    response = handler(request, *args, **kwargs)
  File "/data/app/venv3.7/lib/python3.7/site-packages/rest_framework/decorators.py", line 50, in handler
    return func(*args, **kwargs)
  File "/data/app/PROJECT/projectapp/rest/views.py", line 219, in get_precache_redeemable_codes
    create_ts__gte=arrow.now().replace(months=-1).datetime)) 
  File "/data/app/venv3.7/lib/python3.7/site-packages/arrow/arrow.py", line 807, in replace
    raise AttributeError('unknown attribute: "{}"'.format(key))
AttributeError: unknown attribute: "months"

question from:https://stackoverflow.com/questions/65934136/python-library-arrow-throws-attributeerror-unknown-attribute-months

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)
Waitting for answers

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...