Error in websupport get_metadata

Brad Miller avatarBrad Miller created an issue

Using postgres as storage backend. Using version 1.1.2

I get the following error when I call get_document

Traceback (most recent call last):
  File "/Users/bmiller/src/eds/gluon/restricted.py", line 204, in restricted
    exec ccode in environment
  File "/Users/bmiller/src/eds/applications/eds/controllers/view.py", line 32, in <module>
  File "/Users/bmiller/src/eds/gluon/globals.py", line 172, in <lambda>
    self._caller = lambda f: f()
  File "/Users/bmiller/src/eds/gluon/tools.py", line 2533, in f
    return action(*a, **b)
  File "/Users/bmiller/src/eds/applications/eds/controllers/view.py", line 13, in chapter
    contents = web_support.get_document(doc)
  File "/Library/Python/2.7/site-packages/Sphinx-1.1.2-py2.7.egg/sphinx/websupport/__init__.py", line 199, in get_document
    self.storage.get_metadata(docname, moderator))
  File "/Library/Python/2.7/site-packages/Sphinx-1.1.2-py2.7.egg/sphinx/websupport/storage/sqlalchemystorage.py", line 127, in get_metadata
    return dict([(k, v or 0) for k, v in nodes])
  File "build/bdist.macosx-10.7-intel/egg/sqlalchemy/orm/query.py", line 2057, in __iter__
    return self._execute_and_instances(context)
  File "build/bdist.macosx-10.7-intel/egg/sqlalchemy/orm/query.py", line 2072, in _execute_and_instances
    result = conn.execute(querycontext.statement, self._params)
  File "build/bdist.macosx-10.7-intel/egg/sqlalchemy/engine/base.py", line 1405, in execute
    params)
  File "build/bdist.macosx-10.7-intel/egg/sqlalchemy/engine/base.py", line 1538, in _execute_clauseelement
    compiled_sql, distilled_params
  File "build/bdist.macosx-10.7-intel/egg/sqlalchemy/engine/base.py", line 1646, in _execute_context
    context)
  File "build/bdist.macosx-10.7-intel/egg/sqlalchemy/engine/base.py", line 1639, in _execute_context
    context)
  File "build/bdist.macosx-10.7-intel/egg/sqlalchemy/engine/default.py", line 330, in do_execute
    cursor.execute(statement, parameters)
ProgrammingError: (ProgrammingError) column "sphinx_comments.id" must appear in the GROUP BY clause or be used in an aggregate function
LINE 2: FROM sphinx_nodes LEFT OUTER JOIN (SELECT sphinx_comments.id...
                                                  ^
 'SELECT sphinx_nodes.id AS sphinx_nodes_id, anon_1.comment_count AS anon_1_comment_count \nFROM sphinx_nodes LEFT OUTER JOIN (SELECT sphinx_comments.id AS id, sphinx_comments.node_id AS node_id, count(%(param_1)s) AS comment_count \nFROM sphinx_comments GROUP BY sphinx_comments.node_id) AS anon_1 ON sphinx_nodes.id = anon_1.node_id \nWHERE sphinx_nodes.document = %(document_1)s' {'document_1': 'analysis', 'param_1': '*'}

Note that this error does not occur when storage is set to sqlite

Comments (3)

  1. Brad Miller

    This fixes it, and runs for sqlite and postgresql:

    diff --git a/sphinx/websupport/storage/sqlalchemystorage.py b/sphinx/websupport/storage/sqlalchemystorage.py
    --- a/sphinx/websupport/storage/sqlalchemystorage.py
    +++ b/sphinx/websupport/storage/sqlalchemystorage.py
    @@ -116,7 +116,7 @@
         def get_metadata(self, docname, moderator):
             session = Session()
             subquery = session.query(
    -            Comment.id, Comment.node_id,
    +            Comment.node_id,
                 func.count('*').label('comment_count')).group_by(
                 Comment.node_id).subquery()
             nodes = session.query(Node.id, subquery.c.comment_count).outerjoin(
    
  2. Log in to comment
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.