我正在将我的项目迁移到 Django 1.8,并且收到与“johnny cache. 特别是在“johnny/cache.py/”中。
错误: lib/python2.7/site-packages/johnny/cache.py",第 87 行,在 get_tables_for_query 表中 = set([v[0] for v in getattr(query, 'alias_map', {}).values( )])
TypeError:“BaseTable”对象不支持索引
我在下面包含了错误源自函数的代码。不建议我是否应该使用 'johnny -cache' 以外的其他东西进行缓存会有所帮助和/或有关此错误的含义以及如何修复它的信息。谢谢!
def get_tables_for_query(query):
"""
Takes a Django 'query' object and returns all tables that will be used in
that query as a list. Note that where clauses can have their own
querysets with their own dependent queries, etc.
"""
from django.db.models.sql.where import WhereNode, SubqueryConstraint
from django.db.models.query import QuerySet
tables = set([v[0] for v in getattr(query, 'alias_map', {}).values()])
def get_sub_query_tables(node):
query = node.query_object
if not hasattr(query, 'field_names'):
query = query.values(*node.targets)
else:
query = query._clone()
query = query.query
return set([v[0] for v in getattr(query, 'alias_map',{}).values()])
def get_tables(node, tables):
if isinstance(node, SubqueryConstraint):
return get_sub_query_tables(node)
for child in node.children:
if isinstance(child, WhereNode): # and child.children:
tables = get_tables(child, tables)
elif not hasattr(child, '__iter__'):
continue
else:
for item in (c for c in child if isinstance(c, QuerySet)):
tables += get_tables_for_query(item.query)
return tables
if query.where and query.where.children:
where_nodes = [c for c in query.where.children if isinstance(c, (WhereNode, SubqueryConstraint))]
for node in where_nodes:
tables += get_tables(node, tables)
return list(set(tables))