pi-manage uses sqlite instead of postgresql (SQLALCHEMY_DATABASE_URI not set)
Closed this issue · 3 comments
Hi,
when using the pi-manage command inside the docker container, pi-manage defaults to a sqlite db and doesn't connect the Postgresql database.
root@df44d9e3cf26:/app# pi-manage realm list
Traceback (most recent call last):
File "/opt/privacyidea/lib/python3.9/site-packages/sqlalchemy/engine/base.py", line 1276, in _execute_context
self.dialect.do_execute(
File "/opt/privacyidea/lib/python3.9/site-packages/sqlalchemy/engine/default.py", line 608, in do_execute
cursor.execute(statement, parameters)
**sqlite3.OperationalError: no such table: config**
SQLALCHEMY_DATABASE_URI isn't set for pi.cfg so it defaults to sqlite:
root@9af10d35e6f8:/app# echo $SQLALCHEMY_DATABASE_URI
In pi.cfg:
SQLALCHEMY_DATABASE_URI = os.environ.get('SQLALCHEMY_DATABASE_URI', 'sqlite:////etc/privacyidea/data/privacyidea.db')
Current workaround is setting $SQLALCHEMY_DATABASE_URI in docker-compose:
"SQLALCHEMY_DATABASE_URI: postgresql+psycopg2://${PI_PSQL_USER}:${PI_PSQL_PASSWORD}@${PSQL_DB_HOST}/${PI_PSQL_DB_NAME}"
@patsbin thanks for reporting the issue and providing the workaround. I'll take a look and in case you have a fix you PR is welcome.
Cheer!
The issue caused by exporting SQLALCHEMY_DATABASE_URI in the Docker entry point does not set to the OS environment variable. I'm looking for a way to fix this.
Due to limitations on the Docker entry point on setting SQLALCHEMY_DATABASE_URI environment, I refactor the pi.cfg and start up scripts to set SQLALCHEMY_DATABASE_URI in pi.cfg.