Я получаю следующую ошибку:
AttributeError at /filterrule/createresultset/
'dict' object has no attribute 'filter_query_json'
Вот код:
from django.db import connections
def fetch_filter_rule_sql_from_ui_db(filter_rule_id):
with connections['frontend'].cursor() as cursor:
query = "SELECT id, filter_query_json FROM dmf_filter_rules WHERE id=%s LIMIT 1"
cursor.execute(query, [filter_rule_id])
filter_rule_sql_json = dictfetchall(cursor)[0].filter_query_json
# filter_rule_sql_json = dictfetchall(cursor)[0][filter_query_json]
return filter_rule_sql_json
def dictfetchall(cursor):
"Return all rows from a cursor as a dict"
columns = [col[0] for col in cursor.description]
return [
dict(zip(columns, row))
for row in cursor.fetchall()
]
Результат на dictfetchall(cursor)[0]
:
{
"id": 1,
"filter_query_json": "{\"request_id\":\"341\",\"match_status\":\"1\",\"verdict\":\"Non Match\",\"matched\":\"s_vs_r_image_class_match\"}"
}
Объект выглядит нормально мне, и я подтвердил атрибут filter_query_json
.
Чего не хватает?