Quoting Is Broken For `PGADMIN_CONFIG_CONFIG_DATABASE_URI` Environment Variable.
Introduction
Using an external database by setting the PGADMIN_CONFIG_CONFIG_DATABASE_URI
environment variable only works if the value is enclosed in single quotes. This is not how environment variables are usually used for configuration and it's also not documented anywhere, which makes it very difficult to find the issue.
Describe the Bug
The problem lies in the quoting in the following code in entrypoint.sh:
if [ -n "${PGADMIN_CONFIG_CONFIG_DATABASE_URI}" ]; then
external_config_db_exists=$(cd /pgadmin4/pgadmin/utils && /venv/bin/python3 -c "from check_external_config_db import check_external_config_db; val = check_external_config_db("${PGADMIN_CONFIG_CONFIG_DATABASE_URI}"); print(val)")
fi
Specifically, the string that is passed to python3
:
"from check_external_config_db import check_external_config_db; val = check_external_config_db("${PGADMIN_CONFIG_CONFIG_DATABASE_URI}"); print(val)"
This is already a quoted string, so using double quotes for "${PGADMIN_CONFIG_CONFIG_DATABASE_URI}"
doesn't work. The result is that the environment variable is interpreted literally, surrounded by two separate strings:
"from check_external_config_db import check_external_config_db; val = check_external_config_db("
${PGADMIN_CONFIG_CONFIG_DATABASE_URI}
"); print(val)"
The 3 values are then concatenated and the quotes are lost.
To Reproduce
To reproduce the behavior, follow these steps:
- Run a docker container with an external DB:
docker run -p 80:80 \
-e 'PGADMIN_DEFAULT_EMAIL=user@domain.com' \
-e 'PGADMIN_DEFAULT_PASSWORD=SuperSecret' \
-e 'PGADMIN_CONFIG_CONFIG_DATABASE_URI=postgresql://user:pw@host.5432/db'
dpage/pgadmin4
- See the error.
Expected Behavior
The container should start normally without error.
Error Message
The error message is:
File "<string>", line 1
from check_external_config_db import check_external_config_db; val = check_external_config_db(postgresql://user:pw@host.5432/db); print(val)
^
SyntaxError: invalid syntax
postfix/postlog: starting the Postfix mail system
Traceback (most recent call last):
File "<string>", line 1, in <module>
File "/pgadmin4/config.py", line 954, in <module>
from pgadmin.evaluate_config import evaluate_and_patch_config
File "/pgadmin4/pgadmin/evaluate_config.py", line 63, in <module>
config_distro = import_module_from_path('config_distro',
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/pgadmin4/pgadmin/evaluate_config.py", line 37, in import_module_from_path
spec.loader.exec_module(module)
File "/pgadmin4/config_distro.py", line 12
CONFIG_DATABASE_URI = postgresql://user:pw@host.5432/db
^
SyntaxError: invalid syntax
usage: gunicorn [OPTIONS] [APP_MODULE]
gunicorn: error: argument -t/--timeout: invalid int value: ''
Screenshots
No screenshots are provided as this is a text-based issue.
Desktop (please complete the following information):
- OS: Host OS X 15.3.1, Linux Container
- Version: 9.1
- Mode: Both
- Package type: Container
Additional Context
The problem is the quoting in the code in entrypoint.sh. The string that is passed to python3
is already a quoted string, so using double quotes for "${PGADMIN_CONFIG_CONFIG_DATABASE_URI}"
doesn't work. The result is that the environment variable is interpreted literally, surrounded by two separate strings.
Possible Solutions
There are two possible solutions to this issue:
- Use single quotes:
"from check_external_config_db import check_external_config_db; val = check_external_config_db('${PGADMIN_CONFIG_CONFIG_DATABASE_URI}'); print(val)"
- Escape the double quotes with a backslash
\"
:
"from check_external_config_db import check_external_config_db; val = check_external_config_db(\"${PGADMIN_CONFIG_CONFIG_DATABASE_URI}\"); print(val)"
However, this makes the whole script very fragile, as the same pattern is used for many other variables.
Conclusion
The quoting issue in the PGADMIN_CONFIG_CONFIG_DATABASE_URI
environment variable is a significant problem that makes it difficult to use an external database. The issue is caused by the quoting in the code in entrypoint.sh. The possible solutions are to use single quotes or to escape the double quotes with a backslash \"
. However, this makes the whole script very fragile.
Introduction
In our previous article, we discussed the quoting issue in the PGADMIN_CONFIG_CONFIG_DATABASE_URI
environment variable. In this article, we will provide a Q&A section to help you better understand the issue and its possible solutions.
Q: What is the quoting issue in the PGADMIN_CONFIG_CONFIG_DATABASE_URI
environment variable?
A: The quoting issue is caused by the way the environment variable is used in the code in entrypoint.sh. The string that is passed to python3
is already a quoted string, so using double quotes for "${PGADMIN_CONFIG_CONFIG_DATABASE_URI}"
doesn't work. The result is that the environment variable is interpreted literally, surrounded by two separate strings.
Q: What are the possible solutions to this issue?
A: There are two possible solutions to this issue:
- Use single quotes:
"from check_external_config_db import check_external_config_db; val = check_external_config_db('${PGADMIN_CONFIG_CONFIG_DATABASE_URI}'); print(val)"
- Escape the double quotes with a backslash
\"
:
"from check_external_config_db import check_external_config_db; val = check_external_config_db(\"${PGADMIN_CONFIG_CONFIG_DATABASE_URI}\"); print(val)"
Q: Why are the possible solutions fragile?
A: The possible solutions are fragile because the same pattern is used for many other variables. This means that if you change one variable, you may break the quoting for other variables.
Q: How can I avoid the quoting issue?
A: To avoid the quoting issue, you can use a different approach to pass the environment variable to python3
. For example, you can use a separate variable to store the value of the environment variable and then pass that variable to python3
.
Q: What are the implications of this issue?
A: The implications of this issue are that you may not be able to use an external database with the PGADMIN_CONFIG_CONFIG_DATABASE_URI
environment variable. This may limit your ability to use certain features of the application.
Q: How can I report this issue?
A: You can report this issue to the developers of the application by submitting a bug report. You can also try to fix the issue yourself and submit a pull request with the fix.
Q: What is the current status of this issue?
A: The current status of this issue is that it is a known bug. The developers are aware of the issue and are working on a fix.
Q: When can I expect a fix for this issue?
A: The developers are working on a fix for this issue, but they do not have a specific timeline for when the fix will be available.
Q: How can I stay up-to-date with the latest information on this issue?
A: You can stay up-to-date with the latest information on this issue by following the developers' blog or by subscribing to their newsletter.
Q: What are the next steps for resolving this issue?
A: The next steps for resolving this issue are to continue working on a fix and to test the fix thoroughly to ensure that it does not introduce any new bugs.
Q: How can I help with resolving this issue?
A: You can help with resolving this issue by testing the fix and providing feedback to the developers. You can also try to fix the issue yourself and submit a pull request with the fix.
Q: What are the benefits of resolving this issue?
A: The benefits of resolving this issue are that you will be able to use an external database with the PGADMIN_CONFIG_CONFIG_DATABASE_URI
environment variable, which will give you more flexibility and options for using the application.
Q: What are the risks of not resolving this issue?
A: The risks of not resolving this issue are that you may not be able to use certain features of the application, which may limit your ability to use the application effectively.