markdrago / pgsanity

Check syntax of postgresql sql files
MIT License
316 stars 28 forks source link

ecpg error on new lines #18

Closed yonatan-blue closed 8 years ago

yonatan-blue commented 8 years ago

on running:

from pgsanity.pgsanity import check_string
check_string(sql_command)

with a multi-line sql command I get:
*** Error in `ecpg': munmap_chunk(): invalid pointer: ***
I have found a workaround:

  sql_command = '\n'.join(
        filter(
            lambda line: line.strip() == "",
            sql_command.splitlines()
        )
    )

meaning I remove all empty lines. I tried adding this snippet in: pgsanity.pgsanity.ecpg.check_syntax but it broke the tests:

  .............................F....F.FF..
======================================================================
FAIL: test_simple_failure (test.test_ecpg.TestEcpg)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/home/yonatan/github/pgsanity/test/test_ecpg.py", line 14, in test_simple_failure
    self.assertFalse(success)
AssertionError: True is not false

======================================================================
FAIL: test_check_invalid_string (test.test_pgsanity.TestPgSanity)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/home/yonatan/github/pgsanity/test/test_pgsanity.py", line 34, in test_check_invalid_string
    self.assertFalse(success)
AssertionError: True is not false

======================================================================
FAIL: test_check_invalid_file (test.test_pgsanity.TestPgSanityFiles)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/home/yonatan/github/pgsanity/test/test_pgsanity.py", line 56, in test_check_invalid_file
    self.assertNotEqual(status_code, 0)
AssertionError: 0 == 0

======================================================================
FAIL: test_check_missing_semi (test.test_pgsanity.TestPgSanityFiles)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/home/yonatan/github/pgsanity/test/test_pgsanity.py", line 65, in test_check_missing_semi
    self.assertNotEqual(status_code, 0)
AssertionError: 0 == 0

----------------------------------------------------------------------
Ran 40 tests in 0.020s

FAILED (failures=4)

how can I fix this?

markdrago commented 8 years ago

Can you provide a sql file that reproduces the problem?

yonatan-blue commented 8 years ago

@markdrago following is the string I wanted to check, but, I tried reproducing and it only reproduce on python 3.4.3 and not on python 3.5.2.

CREATE OR REPLACE FUNCTION one_more_function_name(var_name TEXT) RETURNS INTEGER
AS $$
INSERT INTO another_function (var_name)
VALUES (var_name)
RETURNING id;
$$
LANGUAGE SQL;

CREATE OR REPLACE FUNCTION function_name(var_name TEXT) RETURNS INTEGER
AS $$
SELECT function_name(var_name)
$$
LANGUAGE SQL;
markdrago commented 8 years ago

I tried reproducing this and, as you said, it works in python 3.5.2. It also works with python 2.7.12. To be honest, I'm tempted to not make any changes. While I can't back it up, I think the munmap_chunk error is more indicative of a problem in ecpg than in pgsanity. I'd rather not work around it - especially if it works in the latest versions of python2 and python3.

Is it possible that your two tests are using different versions of ecpg as well? Was the python 3.4.3 test and the 3.5.2 test executed on the same machine with the same ecpg?

yonatan-blue commented 8 years ago

@markdrago yes, you are right: I only got the error with:

ecpg (PostgreSQL 9.6.1) 4.12.0  # with python 3.4.3

and with:

ecpg (PostgreSQL 9.5.5) 4.11.0  # with python 3.5.2

I did not get the error.

any how I'm good...

@markdrago thanks for your replay

yonatan-blue commented 8 years ago

tldr; check your ecpg version

markdrago commented 8 years ago

I'm running the same version of ecpg that gave you a problem:

ecpg (PostgreSQL 9.6.1) 4.12.0

I think we'll just hold tight for now and see if anyone else is able to reproduce.