Created
June 25, 2015 18:14
-
-
Save mmulich/52134d5beeaf43da7081 to your computer and use it in GitHub Desktop.
plpydbapi workaround
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
From ff5714e6f56487cebe340590eaef5a2b1ba93282 Mon Sep 17 00:00:00 2001 | |
From: Michael Mulich <[email protected]> | |
Date: Thu, 25 Jun 2015 11:09:20 -0700 | |
Subject: [PATCH] Use dbapi positional arguments for the tree query. | |
This change is necessary because plpydbapi does not implement | |
a way to translate mappings to plpy planned sql arguments. | |
--- | |
cnxarchive/database.py | 2 +- | |
cnxarchive/sql/get-tree-by-uuid-n-version.sql | 4 ++-- | |
cnxarchive/views.py | 7 ++----- | |
3 files changed, 5 insertions(+), 8 deletions(-) | |
diff --git a/cnxarchive/database.py b/cnxarchive/database.py | |
index a31ade7..f6ceb7a 100644 | |
--- a/cnxarchive/database.py | |
+++ b/cnxarchive/database.py | |
@@ -108,7 +108,7 @@ def get_tree(ident_hash, cursor): | |
""" | |
uuid, version = split_ident_hash(ident_hash) | |
cursor.execute(SQL['get-tree-by-uuid-n-version'], | |
- dict(id=uuid, version=version)) | |
+ (uuid, version,)) | |
try: | |
tree = cursor.fetchone()[0] | |
except TypeError: # NoneType | |
diff --git a/cnxarchive/sql/get-tree-by-uuid-n-version.sql b/cnxarchive/sql/get-tree-by-uuid-n-version.sql | |
index 6fa70b9..a82c8bf 100644 | |
--- a/cnxarchive/sql/get-tree-by-uuid-n-version.sql | |
+++ b/cnxarchive/sql/get-tree-by-uuid-n-version.sql | |
@@ -5,5 +5,5 @@ | |
-- See LICENCE.txt for details. | |
-- ### | |
--- arguments: id:string; version:string | |
-SELECT tree_to_json(%(id)s, %(version)s)::json; | |
+-- arguments[positional]: id:string; version:string; | |
+SELECT tree_to_json(%s, %s)::json; | |
diff --git a/cnxarchive/views.py b/cnxarchive/views.py | |
index 932423e..e5b14d4 100644 | |
--- a/cnxarchive/views.py | |
+++ b/cnxarchive/views.py | |
@@ -21,7 +21,7 @@ from . import config | |
from . import cache | |
# FIXME double import | |
from . import database | |
-from .database import SQL | |
+from .database import SQL, get_tree | |
from .search import ( | |
DEFAULT_PER_PAGE, QUERY_TYPES, DEFAULT_QUERY_TYPE, | |
Query, | |
@@ -260,10 +260,7 @@ def _get_content_json(environ=None, ident_hash=None, reqtype=None): | |
result = get_content_metadata(id, version, cursor) | |
if result['mediaType'] == COLLECTION_MIMETYPE: | |
# Grab the collection tree. | |
- query = SQL['get-tree-by-uuid-n-version'] | |
- args = dict(id=result['id'], version=result['version']) | |
- cursor.execute(query, args) | |
- result['tree'] = cursor.fetchone()[0] | |
+ result['tree'] = get_tree(ident_hash, cursor) | |
page_ident_hash = routing_args.get('page_ident_hash') | |
if page_ident_hash: | |
-- | |
2.2.1 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment