pytest-postgresql icon indicating copy to clipboard operation
pytest-postgresql copied to clipboard

Problem calling pg_ctl with "--auth=trust"

Open BrunoCoimbra opened this issue 5 years ago • 14 comments

Hello,

I noticed the changes in 2.5.1 seem to break pytest_postgresql fixtures. The problem happens when pg_ctl tries to call initdb adding the "--auth=trust" parameter:

subprocess.CalledProcessError: Command '['/usr/bin/pg_ctl', 'initdb', '--pgdata', '/tmp/postgresqldata.15455', '-o', '--username=postgres --auth=trust']' returned non-zero exit status 1.

Executing the same command directly on terminal I get:

/usr/bin/pg_ctl initdb --pgdata /tmp/postgresqldata.15455 -o --username=postgres --auth=trust
/usr/bin/pg_ctl: unrecognized option '--auth=trust'
Try "pg_ctl --help" for more information.

Are there new configuration requirements I'm missing, or is it an actual bug?

Thanks, Bruno

BrunoCoimbra avatar Oct 22 '20 16:10 BrunoCoimbra

Could you check v2.5.2 if it still occurs? What system are you on? And did that worked for you before?

fizyk avatar Oct 30 '20 13:10 fizyk

Ok v2.5.2 seems to have solved the problem. We can close this issue. Thanks for the help.

BrunoCoimbra avatar Dec 16 '20 16:12 BrunoCoimbra

I am still experiencing this issue in v2.5.2.

$ python
Python 3.8.6 (default, Oct 13 2020, 20:49:19)
[GCC 8.3.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import pytest_postgresql
>>> pytest_postgresql.__version__
'2.5.2'
>>> exit()
$ /usr/lib/postgresql/11/bin/pg_ctl initdb --pgdata /tmp/postgresqldata.25110 -o --username=postgres --auth=trust
/usr/lib/postgresql/11/bin/pg_ctl: unrecognized option '--auth=trust'
Try "pg_ctl --help" for more information.
$ /usr/lib/postgresql/11/bin/pg_ctl --version
pg_ctl (PostgreSQL) 11.9 (Debian 11.9-0+deb10u1)

michael-burt avatar Dec 18 '20 23:12 michael-burt

If anyone is experiencing this issue, I'll accept tested solution, review pull request, but actually have to time to actively work on it.

fizyk avatar Jan 08 '21 17:01 fizyk

I ran into this problem on Mac.

Turns out it was a stray copy of libpq that didn't support the --auth flag. My solution: remove libpq, remove and reinstall postgres.

davidlee-ca avatar Feb 12 '21 15:02 davidlee-ca

I am using the same version, and I have the same problem, reinstalling did not solve the problem.
Any ideas?

> pg_ctl --version           
pg_ctl (PostgreSQL) 16.1 (Homebrew)
> python3.11 -m pip show pytest-postgresql
Name: pytest-postgresql
Version: 5.0.0
Summary: Postgresql fixtures and fixture factories for Pytest.
Home-page: 
Author: 
Author-email: Grzegorz Śliwiński <[email protected]>
License: 
Location: /opt/homebrew/lib/python3.11/site-packages
Requires: mirakuru, port-for, psycopg, pytest, setuptools
Required-by: 
> pg_ctl initdb --pgdata /XXX/YYY/ZZZ/pytest-postgresql-postgresql_proc0/data-65432 -o --username=myusername --auth=trust                
pg_ctl: unrecognized option `--auth=trust'
Try "pg_ctl --help" for more information.

blelia avatar Jan 28 '24 20:01 blelia

Same here, auth is not recognized

nachonavarro avatar May 27 '24 12:05 nachonavarro

I experienced the same issues, the subprocess.CalledProcessError: Command error, in my main terminal application, but in some other terminals it worked for some reason.

After a bit of digging, it got my tests working again after adding LANG=en_US.UTF-8 in front of my pytest run command.

Adding this env variable in front of the actual command being ran doesn't resolve the pg_ctl: unrecognised option --auth=trust'` issue.

If you find this comment, I hope this might be useful.

realDragonium avatar May 30 '24 12:05 realDragonium

I'm reopening it, @realDragonium that's the first lead I got in this case. I wonder why does it work when using before all pytest command and not if it's used for just pg_ctl 🤔

fizyk avatar Jun 03 '24 09:06 fizyk

Okay, we use envvars for main process start, but here https://github.com/ClearcodeHQ/pytest-postgresql/blob/main/pytest_postgresql/executor.py#L180 it's not used, @realDragonium have you tried it there? (line 180 or line 184?

fizyk avatar Jun 03 '24 09:06 fizyk

Glad to see this issue being reopened!

If i run my test WITH the env var, the subcommand being ran logs the following:

initdb: could not find suitable text search configuration for locale "UTF-8"

If i run my test WITHOUT the env var, i get:

initdb: error: invalid locale settings; check LANG and LC_* environment variables
pg_ctl: database system initialization failed
subprocess.CalledProcessError: Command '['/opt/homebrew/Cellar/postgresql@16/16.3/bin/pg_ctl', 'initdb', '--pgdata', '/private/var/folders/6q/g8ntf_8555lc6m3xzcsjzt4r0000gn/T/pytest-of-drago/pytest-148/pytest-postgresql-postgresql_proc0/data-30269', '-o', '--username=postgres --auth=trust']' returned non-zero exit status 1.

I have confirmed that there is no LANG env var in environment of the subprocess command, when running the test without setting the env var. I did this by printing out the result of running env cmd in subprocess.check_output.

Is this what you're looking for?

realDragonium avatar Jun 04 '24 08:06 realDragonium

okay, but the first is only in logs and the whole test suite runs fine, right?

Would you be able to modify your copy of pytest-postgresql with such diff and see the results?

diff --git a/pytest_postgresql/executor.py b/pytest_postgresql/executor.py
index 2579749..d61acc1 100644
--- a/pytest_postgresql/executor.py
+++ b/pytest_postgresql/executor.py
@@ -177,11 +177,11 @@ def init_directory(self) -> None:
                 password_file.write(password)
                 password_file.flush()
                 init_directory += ["-o", " ".join(options)]
-                subprocess.check_output(init_directory)
+                subprocess.check_output(init_directory, env=self._envvars)
         else:
             options += ["--auth=trust"]
             init_directory += ["-o", " ".join(options)]
-            subprocess.check_output(init_directory)
+            subprocess.check_output(init_directory, env=self._envvars)
 
         self._directory_initialised = True

fizyk avatar Jun 04 '24 09:06 fizyk

okay, but the first is only in logs and the whole test suite runs fine, right?

Yes it does

Would you be able to modify your copy of pytest-postgresql with such diff and see the results?

Yes, it works with the provided modification. (And it stops working when i remove the change)

Awesome!

realDragonium avatar Jun 04 '24 09:06 realDragonium

Okay, got pull request, now to think a bit how to test it.

fizyk avatar Jun 04 '24 10:06 fizyk