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

AttributeError: 'decimal.Decimal' object has no attribute 'total_seconds' #245

Open
peppelinux opened this issue Jun 25, 2017 · 14 comments · May be fixed by #648
Open

AttributeError: 'decimal.Decimal' object has no attribute 'total_seconds' #245

peppelinux opened this issue Jun 25, 2017 · 14 comments · May be fixed by #648

Comments

@peppelinux
Copy link

peppelinux commented Jun 25, 2017

Debian 9, python 3.5.3, Django 1.10.7

python ./manage.py qinfo

Traceback (most recent call last):
  File "./manage.py", line 10, in <module>
    execute_from_command_line(sys.argv)
  File "/opt/arif-envo-cesmma/lib/python3.5/site-packages/django/core/management/__init__.py", line 367, in execute_from_command_line
    utility.execute()
  File "/opt/arif-envo-cesmma/lib/python3.5/site-packages/django/core/management/__init__.py", line 359, in execute
    self.fetch_command(subcommand).run_from_argv(self.argv)
  File "/opt/arif-envo-cesmma/lib/python3.5/site-packages/django/core/management/base.py", line 294, in run_from_argv
    self.execute(*args, **cmd_options)
  File "/opt/arif-envo-cesmma/lib/python3.5/site-packages/django/core/management/base.py", line 345, in execute
    output = self.handle(*args, **options)
  File "/opt/arif-envo-cesmma/lib/python3.5/site-packages/django_q/management/commands/qinfo.py", line 41, in handle
    info()
  File "/opt/arif-envo-cesmma/lib/python3.5/site-packages/django_q/monitor.py", line 128, in info
    exec_time = exec_time['time_taken'].total_seconds() / tasks_per_day
AttributeError: 'decimal.Decimal' object has no attribute 'total_seconds'

if I enable time zone support in django settings I get another fault

Traceback (most recent call last):
  File "./manage.py", line 10, in <module>
    execute_from_command_line(sys.argv)
  File "/opt/arif-envo-cesmma/lib/python3.5/site-packages/django/core/management/__init__.py", line 367, in execute_from_command_line
    utility.execute()
  File "/opt/arif-envo-cesmma/lib/python3.5/site-packages/django/core/management/__init__.py", line 359, in execute
    self.fetch_command(subcommand).run_from_argv(self.argv)
  File "/opt/arif-envo-cesmma/lib/python3.5/site-packages/django/core/management/base.py", line 294, in run_from_argv
    self.execute(*args, **cmd_options)
  File "/opt/arif-envo-cesmma/lib/python3.5/site-packages/django/core/management/base.py", line 345, in execute
    output = self.handle(*args, **options)
  File "/opt/arif-envo-cesmma/lib/python3.5/site-packages/django_q/management/commands/qinfo.py", line 41, in handle
    info()
  File "/opt/arif-envo-cesmma/lib/python3.5/site-packages/django_q/monitor.py", line 127, in info
    exec_time = last_tasks.aggregate(time_taken=Sum(F('stopped') - F('started')))
  File "/opt/arif-envo-cesmma/lib/python3.5/site-packages/django/db/models/query.py", line 356, in aggregate
    return query.get_aggregation(self.db, kwargs.keys())
  File "/opt/arif-envo-cesmma/lib/python3.5/site-packages/django/db/models/sql/query.py", line 462, in get_aggregation
    result = compiler.apply_converters(result, converters)
  File "/opt/arif-envo-cesmma/lib/python3.5/site-packages/django/db/models/sql/compiler.py", line 779, in apply_converters
    value = converter(value, expression, self.connection, self.query.context)
  File "/opt/arif-envo-cesmma/lib/python3.5/site-packages/django/db/backends/mysql/operations.py", line 208, in convert_datetimefield_value
    value = timezone.make_aware(value, self.connection.timezone)
  File "/opt/arif-envo-cesmma/lib/python3.5/site-packages/django/utils/timezone.py", line 368, in make_aware
    return timezone.localize(value, is_dst=is_dst)
  File "/opt/arif-envo-cesmma/lib/python3.5/site-packages/pytz/__init__.py", line 225, in localize
    if dt.tzinfo is not None:
AttributeError: 'decimal.Decimal' object has no attribute 'tzinfo'

@Eagllus
Copy link
Collaborator

Eagllus commented Jun 27, 2017

@peppelinux could you give a bit more information about your system.
It works for myself on my machine with the following:

  • Django (1.11) also on (1.11.2)
  • Django-q (0.8.0)

I run macOS Sierra (v10.12.5)

@peppelinux
Copy link
Author

as already wrote:
Debian 9, python 3.5.3, Django 1.10.7

django-q version is the latest stable

@Eagllus
Copy link
Collaborator

Eagllus commented Jun 27, 2017

Sorry, first drink coffee then read stuff... I tried django 1.10.7 with djang-q but din't get any errors.
Unfortunately I can't check on Debian or Python 3.5.

@peppelinux
Copy link
Author

Thank you very much,

I really appreciate your share, I'll do my best with some trials before update, and hopefully close, this issue.

@bob-r
Copy link

bob-r commented Jul 6, 2017

I had the same issue #224

@peppelinux
Copy link
Author

peppelinux commented Jul 6, 2017

With python2 it doesn't exist, I had this exception with python 3.5 but I should do some other accurate tests

@Eagllus
Copy link
Collaborator

Eagllus commented Feb 6, 2018

@peppelinux any update on this?

@naughtyGitCat
Copy link

naughtyGitCat commented Feb 15, 2019

Python 3.6 mac django2

run qinfo

same issue

@saranshbansal
Copy link

python 3.6
django 2.0.3

python manage.py qinfo

Same issue.

@natebessa
Copy link

python 3.7.3
django 2.1.7

python manage.py qinfo

Same issue for me as well.

@bbaobelief
Copy link

python 3.7.3
django 2.2.12
mysql 5.7

python manage.py qinfo

Same issue for me as well.

@ikarys
Copy link

ikarys commented Jul 30, 2020

Hi,

I have the same issue.
If we investigate in the file monitor.py, we see in line 204 that the object exec_time["time_taken" has type "decimal.Decimal".

But the method "total_seconds()" it's a timedelta method.
https://docs.python.org/2/library/datetime.html#datetime.timedelta.total_seconds

            exec_time = last_tasks.aggregate(
                time_taken=Sum(F("stopped") - F("started"))
            )

            exec_time = exec_time["time_taken"].total_seconds() / tasks_per_day```

@Koed00
Copy link
Owner

Koed00 commented Jul 31, 2020 via email

@HsinM
Copy link

HsinM commented Feb 1, 2022

I have the same issue @ version 1.3.9 on Redis 5.0.14, MariaDB 10.3.29 and Python 3.9.1

My temp solution is delete .total_seconds().

Thank You~

@HsinM HsinM linked a pull request Feb 2, 2022 that will close this issue
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.

10 participants