pg8000 adapter doesn't send native Numerics

Issue #2132 resolved
Former user created an issue

class _PGNumeric in pg8000.py needs these lines to turn on sending of Numerics:

    def bind_processor(self, dialect):
        return None

psycopg2.py has the same code. If this code is not present, sqltypes.Numeric will force conversion to float instead of passing a decimal.Decimal.

pg8000 1.08 appears to have a bug where it truncates decimals after the decimal point. See also https://github.com/mfenniak/pg8000/issues/7 for this bug.

Comments (4)

  1. Mike Bayer repo owner

    the patch as is causes float coercion to fail, in a way that does not occur with psycopg2:

    ======================================================================
    FAIL: test.sql.test_types.NumericTest.test_float_as_decimal
    ----------------------------------------------------------------------
    Traceback (most recent call last):
      File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/nose/case.py", line 187, in runTest
        self.test(*self.arg)
      File "/Users/classic/dev/sqlalchemy/./test/sql/test_types.py", line 1363, in test_float_as_decimal
        filter_ = lambda n:n is not None and round(n, 5) or None
      File "<string>", line 1, in <lambda>
      File "/Users/classic/dev/sqlalchemy/./test/lib/testing.py", line 340, in decorate
        return fn(*args, **kw)
      File "/Users/classic/dev/sqlalchemy/./test/sql/test_types.py", line 1336, in _do_test
        eq_(result, output)
      File "/Users/classic/dev/sqlalchemy/./test/lib/testing.py", line 499, in eq_
        assert a == b, msg or "%r != %r" % (a, b)
    AssertionError: set([15.7563, None](16.0,)) != set([None](15.7563,))
    
    ======================================================================
    FAIL: test.sql.test_types.NumericTest.test_float_as_float
    ----------------------------------------------------------------------
    Traceback (most recent call last):
      File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/nose/case.py", line 187, in runTest
        self.test(*self.arg)
      File "/Users/classic/dev/sqlalchemy/./test/sql/test_types.py", line 1371, in test_float_as_float
        filter_ = lambda n:n is not None and round(n, 5) or None
      File "<string>", line 1, in <lambda>
      File "/Users/classic/dev/sqlalchemy/./test/lib/testing.py", line 340, in decorate
        return fn(*args, **kw)
      File "/Users/classic/dev/sqlalchemy/./test/sql/test_types.py", line 1336, in _do_test
        eq_(result, output)
      File "/Users/classic/dev/sqlalchemy/./test/lib/testing.py", line 499, in eq_
        assert a == b, msg or "%r != %r" % (a, b)
    AssertionError: set([15.7563](16.0,)) != set([15.7563](15.7563))
    
    ----------------------------------------------------------------------
    

    an adjustment is to disable bind processing for Numeric but not Float. I have a patch here that accomplishes that.

  2. Log in to comment