Skip to content
This repository

SettingsDebugPanel doesn't work with pymongo #30

Closed
zigsla opened this Issue September 19, 2011 · 4 comments

3 participants

zigsla Reed O'Brien Chris McDonough
zigsla

SettingsDebugPanel doesn't work with pymongo

Traceback (most recent call last):
  File "/home/Documents/development/venvs/pyramid-1.2-venv/local/lib/python2.7/site-packages/paste/httpserver.py", line 1068, in process_request_in_thread
    self.finish_request(request, client_address)
  File "/usr/lib/python2.7/SocketServer.py", line 323, in finish_request
    self.RequestHandlerClass(request, client_address, self)
  File "/usr/lib/python2.7/SocketServer.py", line 639, in __init__
    self.handle()
  File "/home/Documents/development/venvs/pyramid-1.2-venv/local/lib/python2.7/site-packages/paste/httpserver.py", line 442, in handle
    BaseHTTPRequestHandler.handle(self)
  File "/usr/lib/python2.7/BaseHTTPServer.py", line 343, in handle
    self.handle_one_request()
  File "/home/Documents/development/venvs/pyramid-1.2-venv/local/lib/python2.7/site-packages/paste/httpserver.py", line 437, in handle_one_request
    self.wsgi_execute()
  File "/home/Documents/development/venvs/pyramid-1.2-venv/local/lib/python2.7/site-packages/paste/httpserver.py", line 287, in wsgi_execute
    self.wsgi_start_response)
  File "/home/Documents/development/venvs/pyramid-1.2-venv/local/lib/python2.7/site-packages/pyramid/router.py", line 176, in __call__
    response = self.handle_request(request)
  File "/home/Documents/development/venvs/pyramid-1.2-venv/local/lib/python2.7/site-packages/pyramid_debugtoolbar/toolbar.py", line 150, in toolbar_tween
    toolbar.process_response(response)
  File "/home/Documents/development/venvs/pyramid-1.2-venv/local/lib/python2.7/site-packages/pyramid_debugtoolbar/toolbar.py", line 50, in process_response
    vars, request=request)
  File "/home/Documents/development/venvs/pyramid-1.2-venv/local/lib/python2.7/site-packages/pyramid/renderers.py", line 69, in render
    return helper.render(value, None, request=request)
  File "/home/Documents/development/venvs/pyramid-1.2-venv/local/lib/python2.7/site-packages/pyramid/renderers.py", line 418, in render
    result = renderer(value, system_values)
  File "/home/Documents/development/venvs/pyramid-1.2-venv/local/lib/python2.7/site-packages/pyramid_jinja2/__init__.py", line 277, in __call__
    return self.template.render(system)
  File "/home/Documents/development/venvs/pyramid-1.2-venv/local/lib/python2.7/site-packages/jinja2/environment.py", line 894, in render
    return self.environment.handle_exception(exc_info, True)
  File "/home/Documents/development/venvs/pyramid-1.2-venv/local/lib/python2.7/site-packages/pyramid_debugtoolbar/templates/toolbar.jinja2", line 62, in top-level template code
    {{ panel.content()|safe }}
  File "/home/Documents/development/venvs/pyramid-1.2-venv/local/lib/python2.7/site-packages/pyramid_debugtoolbar/panels/settings.py", line 57, in content
    vars, self.request)
  File "/home/Documents/development/venvs/pyramid-1.2-venv/local/lib/python2.7/site-packages/pyramid_debugtoolbar/panels/__init__.py", line 24, in render
    return render(template_name, vars, request=request)
  File "/home/Documents/development/venvs/pyramid-1.2-venv/local/lib/python2.7/site-packages/pyramid/renderers.py", line 69, in render
    return helper.render(value, None, request=request)
  File "/home/Documents/development/venvs/pyramid-1.2-venv/local/lib/python2.7/site-packages/pyramid/renderers.py", line 418, in render
    result = renderer(value, system_values)
  File "/home/Documents/development/venvs/pyramid-1.2-venv/local/lib/python2.7/site-packages/pyramid_jinja2/__init__.py", line 277, in __call__
    return self.template.render(system)
  File "/home/Documents/development/venvs/pyramid-1.2-venv/local/lib/python2.7/site-packages/jinja2/environment.py", line 894, in render
    return self.environment.handle_exception(exc_info, True)
  File "/home/Documents/development/venvs/pyramid-1.2-venv/local/lib/python2.7/site-packages/pyramid_debugtoolbar/panels/templates/settings.jinja2", line 12, in top-level template code
    <td>{{ value|escape }}</td>
  File "/home/Documents/development/venvs/pyramid-1.2-venv/local/lib/python2.7/site-packages/pymongo/database.py", line 682, in __call__
    "failing because no such method exists." % self.__name)
TypeError: 'Database' object is not callable. If you meant to call the '__html__' method on a 'Connection' object it is failing because no such method exists.
Reed O'Brien
Collaborator

It works with pymongo here.

Reed O'Brien reedobrien closed this September 19, 2011
Reed O'Brien reedobrien reopened this September 19, 2011
Reed O'Brien
Collaborator

sorry didn' t mean to close it; only comment

zigsla

If you follow https://docs.pylonsproject.org/projects/pyramid_cookbook/dev/mongo.html

and your pymongo Connection is in reqistry settings, then it doesn't work

conn = pymongo.Connection(db_uri)
config.registry.settings['db_conn'] = conn

Reed O'Brien
Collaborator

my mongo connection looks something like:

...
from zope.interface import Interface
...
from pyramid.events import subscriber
...

class IMongoDBConnection(Interface):
    """
    marker interface
    """
    pass

def get_mongodb(registry):
    db_name = registry.settings['db_name']
    db = registry.getUtility(IMongoDBConnection)[db_name]
    db.add_son_manipulator(ColanderNullTransformer())
    return db


@subscriber(INewRequest)
def add_mongodb(event):
    db = get_mongodb(event.request.registry)
    event.request.db = db
    event.request.fs = GridFS(db)


def register_mongodb(config, db_uri, slave_okay=False):
    conn = pymongo.Connection(db_uri, slave_okay=slave_okay)
    config.registry.registerUtility(conn, IMongoDBConnection)
    return conn
Chris McDonough mcdonc closed this in 5b1ad07 September 27, 2011
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.