Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

PostgresNode.safe_psql(filename) does not detect syntax errors #52

Closed
cbandy opened this issue Jul 17, 2018 · 6 comments
Closed

PostgresNode.safe_psql(filename) does not detect syntax errors #52

cbandy opened this issue Jul 17, 2018 · 6 comments
Labels
bug

Comments

@cbandy
Copy link

@cbandy cbandy commented Jul 17, 2018

It took me some time to discover that a syntax error was being not being reported by node.safe_psql(filename='some.sql'). I tracked it down to behavior in psql. It seems worth raising, though I'm not certain it is something that testgres is necessarily responsible for handling.


$ psql --version
psql (PostgreSQL) 9.6.4

and/or

$ psql --version
psql (PostgreSQL) 10.4

psql reports errors differently depending on how input is passed:

  1. $ psql -h 127.0.0.1 -U cbandy -X -A -t -q -c 'whoops' -p 34751 postgres ; echo $?
    ERROR:  syntax error at or near "whoops"
    LINE 1: whoops
            ^
    1
    
  2. N.B. exit code is zero here:

    $ psql -h 127.0.0.1 -U cbandy -X -A -t -q -f <( echo 'whoops' ) -p 34751 postgres ; echo $?
    psql:/dev/fd/63:1: ERROR:  syntax error at or near "whoops"
    LINE 1: whoops
            ^
    0
    
  3. $ psql -h 127.0.0.1 -U cbandy -X -A -t -q -v ON_ERROR_STOP=1 -f <( echo 'whoops' ) -p 34751 
    postgres ; echo $?
    psql:/dev/fd/63:1: ERROR:  syntax error at or near "whoops"
    LINE 1: whoops
            ^
    3
    
@funbringer
Copy link
Collaborator

@funbringer funbringer commented Jul 17, 2018

Hi Chris,

Thanks for the report! I'll definitely fix this.

@funbringer funbringer added the bug label Jul 17, 2018
@funbringer
Copy link
Collaborator

@funbringer funbringer commented Jul 17, 2018

This is really odd, but we should provide a workaround nevertheless. I guess it's worth starting a thread in pgsql-hackers.

@funbringer
Copy link
Collaborator

@funbringer funbringer commented Jul 17, 2018

ON_ERROR_STOP=1

Now the question is whether we should add this option to psql's args by default. I'd like to, but this might break some other user's expectations.

EDIT: at first I didn't notice you mentioning ON_ERROR_STOP.

@ildus
Copy link
Collaborator

@ildus ildus commented Jul 18, 2018

I suggest to change environment in safe_psql and keep old behavior in psql.

funbringer added a commit that referenced this issue Jul 18, 2018
ildus added a commit that referenced this issue Jul 18, 2018
safe_psql() should always raise error on wrong input (issue #52)
@funbringer
Copy link
Collaborator

@funbringer funbringer commented Jul 18, 2018

Fixed in 1.8.2.

@funbringer funbringer closed this Jul 18, 2018
@cbandy
Copy link
Author

@cbandy cbandy commented Jul 18, 2018

Thank you for such a quick response!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
3 participants
You can’t perform that action at this time.