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

Datastore problem with ckan2.7 #23

Open
roll opened this issue Nov 25, 2018 · 0 comments
Open

Datastore problem with ckan2.7 #23

roll opened this issue Nov 25, 2018 · 0 comments

Comments

@roll
Copy link
Contributor

roll commented Nov 25, 2018

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

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

1 participant