Coder Social home page Coder Social logo

Comments (5)

haizaar avatar haizaar commented on May 29, 2024

Hi Chen,
Thanks for the report.

As a quick check, can you try this cursor class with plain psycopg2 in your
environment?
On Apr 26, 2014 8:13 PM, "Chen Tao" [email protected] wrote:

Greetings. As the title suggests, getconn() doesn't play well with
NamedTupleCursor.

Here's a test case:

import psycopg2
import momoko
from psycopg2.extras import NamedTupleCursor
from tornado.testing import AsyncTestCase, gen_test
import unittest
import os

class ConnNamedTuple(AsyncTestCase):
def setUp(self):
super().setUp()
self.db = momoko.Pool(
dsn='dbname=dbdb user=%s host=localhost port=5432' % os.environ['USER'],
size=3,
ioloop=self.io_loop,
callback=self.stop,
cursor_factory=NamedTupleCursor
)
self.wait()

def tearDown(self):
    self.db.close()
    self.io_loop.close()

@gen_test
def test_conn_namedtuple(self):
    yield momoko.Op(self.db.getconn)

unittest.main()

Here's the stack trace:

ERROR: test_conn_namedtuple (main.ConnNamedTuple)

Traceback (most recent call last):
File "/usr/local/lib/python3.4/dist-packages/tornado/testing.py", line 427, in wrapper
functools.partial(f, self), timeout=timeout)
File "/usr/local/lib/python3.4/dist-packages/tornado/ioloop.py", line 389, in run_sync
return future_cell[0].result()
File "/usr/local/lib/python3.4/dist-packages/tornado/concurrent.py", line 129, in result
raise_exc_info(self.**exc_info)
File "", line 3, in raise_exc_info
File "/usr/local/lib/python3.4/dist-packages/tornado/gen.py", line 206, in handle_exception
if runner is not None and runner.handle_exception(typ, value, tb):
File "/usr/local/lib/python3.4/dist-packages/tornado/gen.py", line 580, in handle_exception
self.run()
File "/usr/local/lib/python3.4/dist-packages/tornado/gen.py", line 529, in run
yielded = self.gen.throw(_exc_info)
File "tmp/conn_namedtuple.py", line 26, in test_conn_namedtuple
yield momoko.Op(self.db.getconn)
File "/usr/local/lib/python3.4/dist-packages/tornado/stack_context.py", line 302, in wrapped
ret = fn(_args, kwargs)
File "/usr/local/lib/python3.4/dist-packages/momoko/connection.py", line 594, in io_callback
self.callback(None)
File "/usr/local/lib/python3.4/dist-packages/momoko/connection.py", line 640, in _ping_callback
cursor.fetchall()
File "/usr/local/lib/python3.4/dist-packages/psycopg2/extras.py", line 317, in fetchall
nt = self.Record = self._make_nt()
File "/usr/local/lib/python3.4/dist-packages/psycopg2/extras.py", line 340, in _make_nt
return namedtuple("Record", [d[0] for d in self.description or ()])
File "/usr/lib/python3.4/collections/__init
.py", line 338, in namedtuple
'identifiers: %r' % name)
ValueError: Type names and field names must be valid identifiers: '?column?'


Ran 1 test in 0.031s

FAILED (errors=1)

I'm on Python 3.4. pip freeze output, all are PyPI releases.

Momoko==1.1.2
psycopg2==2.5.2
tornado==3.2

I think it's easy to workaround but it's a little bit annoying. Thanks in
advance.


Reply to this email directly or view it on GitHubhttps://github.com//issues/74
.

from momoko.

jagt avatar jagt commented on May 29, 2024

@haizaar

You're right it's the same problem with psycopg2. I'm closing this and will report there. Thanks!

from momoko.

encorehu avatar encorehu commented on May 29, 2024

this is actually momoko's error

see psycopg/psycopg2#211

cur.execute("SELECT 'ok';")

need to be:

cur.execute("SELECT 'ok' as blah;")

if you used NamedTupleCursor.

AND, the error occured at connection.py line 635

cursor.execute("SELECT 1")

and i modified it to

cursor.execute("SELECT 1 as ping")

which temp fixed.

from momoko.

haizaar avatar haizaar commented on May 29, 2024

You are right - this is a real bug.

from momoko.

indarian avatar indarian commented on May 29, 2024

Hello! It seems like the same error exists with register_hstore():

Traceback (most recent call last):
      File "/usr/local/lib/python3.4/dist-packages/tornado/ioloop.py", line 565, in _run_callback
        ret = callback()
      File "/usr/local/lib/python3.4/dist-packages/tornado/stack_context.py", line 275, in null_wrapper
        return fn(*args, **kwargs)
      File "/usr/local/lib/python3.4/dist-packages/momoko/connection.py", line 864, in _register
        oid, array_oid = cursor.fetchone()
      File "/usr/local/lib/python3.4/dist-packages/psycopg2/extras.py", line 303, in fetchone
        nt = self.Record = self._make_nt()
      File "/usr/local/lib/python3.4/dist-packages/psycopg2/extras.py", line 340, in _make_nt
        return namedtuple("Record", [d[0] for d in self.description or ()])
      File "/usr/lib/python3.4/collections/__init__.py", line 348, in namedtuple
        raise ValueError('Encountered duplicate field name: %r' % name)
    ValueError: Encountered duplicate field name: 'oid'

I guess it is needed to use aliases as in this issue on this line:
https://github.com/FSX/momoko/blob/master/momoko/connection.py#L890

from momoko.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.