Issue: PostgresqlExtDatabase unsupported psycopg2cffi
Author: cutso
State: closed
Created: 2015-09-20 00:30:35

Peewee is a nice project, thank you!

Today, i have a problem with peewee when used psycopg2cffi connect to postgresql. 
As i run programm under a virtual environ with pypy-2.6.1, that can not install psycopg2, so i used psycpog2cffi instead.

Everything wroks well but PostgresqlExtDatabase.

I do not know why, then i use python 2.7.3 and create virtual environ directly and use psycopg2, it works well.

My connnecting code are:
from playhouse.postgres_ext import PostgresqlExtDatabase
psql_db = PostgresqlExtDatabase('mydb', user="postgres", password="mypass", host="127.0.0.1")
        psql_db.connect()

The problem was happened when use pypy + psycopg2cffi + PostgresqlExtDatabase
Can anybody helps? 
Thank you!

Here are the error log:

Traceback (most recent call last):
  File "/Users/cutso/server/pyenv/1.8.3/lib/python2.7/site-packages/tornado/web.py", line 1415, in _execute
    result = yield result
  File "/Users/cutso/server/pyenv/1.8.3/lib/python2.7/site-packages/tornado/gen.py", line 870, in run
    value = future.result()
  File "/Users/cutso/server/pyenv/1.8.3/lib/python2.7/site-packages/tornado/concurrent.py", line 215, in result
    raise_exc_info(self._exc_info)
  File "/Users/cutso/server/pyenv/1.8.3/lib/python2.7/site-packages/tornado/gen.py", line 879, in run
    yielded = self.gen.send(value)
  File "/Users/cutso/Documents/projects/fancalno/app/default/handlers.py", line 21, in get
    self.render("index.html", users=users, result=result, total=total)
  File "/Users/cutso/server/pyenv/1.8.3/lib/python2.7/site-packages/tornado/web.py", line 704, in render
    html = self.render_string(template_name, **kwargs)
  File "/Users/cutso/Documents/projects/fancalno/app/template.py", line 33, in render_string
    auto_reload=self.settings['debug'], **context)
  File "/Users/cutso/Documents/projects/fancalno/app/template.py", line 42, in _jinja_render
    self.write(template.render(**context))
  File "/Users/cutso/server/pyenv/1.8.3/lib/python2.7/site-packages/jinja2/environment.py", line 989, in render
    return self.environment.handle_exception(exc_info, True)
  File "/Users/cutso/server/pyenv/1.8.3/lib/python2.7/site-packages/jinja2/environment.py", line 754, in handle_exception
    reraise(exc_type, exc_value, tb)
  File "/Users/cutso/Documents/projects/fancalno/template/index.html", line 1, in top-level template code
    {% extends "base.html" %}
  File "/Users/cutso/Documents/projects/fancalno/template/base.html", line 22, in top-level template code
    {% block body %}
  File "/Users/cutso/Documents/projects/fancalno/template/index.html", line 9, in block "body"
    <ul>{% for user in users %}
  File "/Users/cutso/server/pyenv/1.8.3/lib/python2.7/site-packages/peewee.py", line 2794, in __iter__
    return iter(self.execute())
  File "/Users/cutso/server/pyenv/1.8.3/lib/python2.7/site-packages/peewee.py", line 2787, in execute
    self._qr = ResultWrapper(model_class, self._execute(), query_meta)
  File "/Users/cutso/server/pyenv/1.8.3/lib/python2.7/site-packages/peewee.py", line 2470, in _execute
    return self.database.execute_sql(sql, params, self.require_commit)
  File "/Users/cutso/server/pyenv/1.8.3/lib/python2.7/site-packages/playhouse/postgres_ext.py", line 358, in execute_sql
    cursor = self.get_cursor()
  File "/Users/cutso/server/pyenv/1.8.3/lib/python2.7/site-packages/playhouse/postgres_ext.py", line 345, in get_cursor
    return self.get_conn().cursor()
  File "/Users/cutso/server/pyenv/1.8.3/lib/python2.7/site-packages/peewee.py", line 3148, in get_conn
    self.connect()
  File "/Users/cutso/server/pyenv/1.8.3/lib/python2.7/site-packages/peewee.py", line 3128, in connect
    **self.connect_kwargs)
  File "/Users/cutso/server/pyenv/1.8.3/lib/python2.7/site-packages/playhouse/postgres_ext.py", line 375, in _connect
    register_hstore(conn, globally=True)
  File "/Users/cutso/server/pyenv/1.8.3/lib/python2.7/site-packages/psycopg2/extras.py", line 772, in register_hstore
    oid = HstoreAdapter.get_oids(conn_or_curs)
  File "/Users/cutso/server/pyenv/1.8.3/lib/python2.7/site-packages/psycopg2/extras.py", line 712, in get_oids
    conn, curs = _solve_conn_curs(conn_or_curs)
  File "/Users/cutso/server/pyenv/1.8.3/lib/python2.7/site-packages/psycopg2/extras.py", line 599, in _solve_conn_curs
    curs = conn.cursor(cursor_factory=_cursor)
  File "/Users/cutso/server/pyenv/1.8.3/lib/python2.7/site-packages/psycopg2cffi/_impl/connection.py", line 333, in cursor
    cur = cursor_factory(self, name)
TypeError: argument 1 must be psycopg2.extensions.connection, not Connection


Try passing in `register_hstore=False`:

``` python
db = PostgresqlExtDatabase('my_db', register_hstore=False)
```

Looks like the psycopg2.extras helper I was using to register_hstore does not accept the psycopg2cffi `Connection` object.