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 Format for duration arithmetic #3

Closed
agieocean opened this issue Aug 6, 2020 · 1 comment
Closed

AttributeError Format for duration arithmetic #3

agieocean opened this issue Aug 6, 2020 · 1 comment

Comments

@agieocean
Copy link

Error:

Environment:


Request Method: GET
Request URL: http://127.0.0.1:8000/admin/

Django Version: 3.0.4
Python Version: 3.7.6
Installed Applications:
['django.contrib.admin',
 'django.contrib.auth',
 'django.contrib.contenttypes',
 'django.contrib.sessions',
 'django.contrib.messages',
 'django.contrib.staticfiles',
 'django_countries',
 'languages',
 'blacklist',
 'taggit',
 'user',
 'model',
 'administrator']
Installed Middleware:
['django.middleware.security.SecurityMiddleware',
 'django.contrib.sessions.middleware.SessionMiddleware',
 'django.middleware.common.CommonMiddleware',
 'django.middleware.csrf.CsrfViewMiddleware',
 'django.contrib.auth.middleware.AuthenticationMiddleware',
 'django.contrib.messages.middleware.MessageMiddleware',
 'django.middleware.clickjacking.XFrameOptionsMiddleware',
 'blacklist.middleware.blacklist_middleware']



Traceback (most recent call last):
  File "D:\anaconda3\lib\site-packages\django\core\handlers\exception.py", line 34, in inner
    response = get_response(request)
  File "D:\anaconda3\lib\site-packages\blacklist\middleware.py", line 40, in middleware
    _load_blacklist()
  File "D:\anaconda3\lib\site-packages\blacklist\middleware.py", line 98, in _load_blacklist
    for rule in rules:
  File "D:\anaconda3\lib\site-packages\django\db\models\query.py", line 276, in __iter__
    self._fetch_all()
  File "D:\anaconda3\lib\site-packages\django\db\models\query.py", line 1261, in _fetch_all
    self._result_cache = list(self._iterable_class(self))
  File "D:\anaconda3\lib\site-packages\django\db\models\query.py", line 115, in __iter__
    for row in compiler.results_iter(chunked_fetch=self.chunked_fetch, chunk_size=self.chunk_size):
  File "D:\anaconda3\lib\site-packages\django\db\models\sql\compiler.py", line 1103, in results_iter
    results = self.execute_sql(MULTI, chunked_fetch=chunked_fetch, chunk_size=chunk_size)
  File "D:\anaconda3\lib\site-packages\django\db\models\sql\compiler.py", line 1138, in execute_sql
    sql, params = self.as_sql()
  File "D:\anaconda3\lib\site-packages\django\db\models\sql\compiler.py", line 490, in as_sql
    extra_select, order_by, group_by = self.pre_sql_setup()
  File "D:\anaconda3\lib\site-packages\django\db\models\sql\compiler.py", line 51, in pre_sql_setup
    self.setup_query()
  File "D:\anaconda3\lib\site-packages\django\db\models\sql\compiler.py", line 42, in setup_query
    self.select, self.klass_info, self.annotation_col_map = self.get_select()
  File "D:\anaconda3\lib\site-packages\django\db\models\sql\compiler.py", line 257, in get_select
    sql, params = self.compile(col)
  File "D:\anaconda3\lib\site-packages\django\db\models\sql\compiler.py", line 422, in compile
    sql, params = node.as_sql(self, self.connection)
  File "D:\anaconda3\lib\site-packages\django\db\models\aggregates.py", line 88, in as_sql
    return super().as_sql(compiler, connection, **extra_context)
  File "D:\anaconda3\lib\site-packages\django\db\models\expressions.py", line 633, in as_sql
    arg_sql, arg_params = compiler.compile(arg)
  File "D:\anaconda3\lib\site-packages\django\db\models\sql\compiler.py", line 422, in compile
    sql, params = node.as_sql(self, self.connection)
  File "D:\anaconda3\lib\site-packages\django\db\models\expressions.py", line 448, in as_sql
    return DurationExpression(self.lhs, self.connector, self.rhs).as_sql(compiler, connection)
  File "D:\anaconda3\lib\site-packages\django\db\models\expressions.py", line 494, in as_sql
    sql, params = self.compile(self.rhs, compiler, connection)
  File "D:\anaconda3\lib\site-packages\django\db\models\expressions.py", line 484, in compile
    return connection.ops.format_for_duration_arithmetic(sql), params

Exception Type: AttributeError at /admin/
Exception Value: 'DatabaseOperations' object has no attribute 'format_for_duration_arithmetic'

Perhaps of note: I am using djongo

@vsemionov
Copy link
Owner

Indeed, from the above exception it seems that djongo does not implement duration arithmetic. Unfortunately, this arithmetic is required by the code to load only rules that are still active. djongo is not supported, but I think you can easily modify the code to remove this arithmetic. Try editing middleware._load_blacklist() and removing the calls to annotate() and filter(). This will load all blacklist rules from the database, even the ones that have expired. Optionally, you can also implement your own filtering in the for loop, to avoid processing expired rules.

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

No branches or pull requests

2 participants