docker-ckan
docker-ckan copied to clipboard
Datastore problem with ckan2.7
Overview
With this line in Dockerfile we solve the psycopg2 bug related to postgresql-client@10:
# Workaround to solve https://github.com/psycopg/psycopg2/issues/594 in Alpine 3.7
sed -i -e "s/psycopg2==2.4.5/psycopg2==2.7.3.2/g" requirements.txt && \
But at the same time it seems there are breaking changes between these versions of psycopg. For example a query like this:
http://ckan-dev:5000/api/3/action/datastore_search_sql?sql=SELECT%20DISTINCT%20%22Sex%22%20FROM%20%22723c1bca-c4da-4a84-b99b-7140e242921f%22
will fail because of the fact that the latter psycopg returns already parsed dict instead of JSON:
ckan/ckanext/datastore/helpers.py
query_plan = json.loads(result['QUERY PLAN'])
plan = query_plan[0]['Plan']
I was able to solve it patching CKAN:
diff --git a/ckanext/datastore/helpers.py b/ckanext/datastore/helpers.py
index b616f0f94..ec1428d1d 100644
--- a/ckanext/datastore/helpers.py
+++ b/ckanext/datastore/helpers.py
@@ -105,8 +105,8 @@ def get_table_names_from_sql(context, sql):
table_names = []
try:
- query_plan = json.loads(result['QUERY PLAN'])
- plan = query_plan[0]['Plan']
+ # TODO: add comment and issue
+ plan = result['QUERY PLAN'][0]['Plan']
table_names.extend(_get_table_names_from_plan(plan))
But it's only for this exact problem - not sure are there other breaking changes in psycopg2