mealie-recipes / mealie

Mealie is a self hosted recipe manager and meal planner with a RestAPI backend and a reactive frontend application built in Vue for a pleasant user experience for the whole family. Easily add recipes into your database by providing the url and mealie will automatically import the relevant data or add a family recipe with the UI editor
https://docs.mealie.io
GNU Affero General Public License v3.0
5.67k stars 617 forks source link

[BUG] - POSTGRES_URL_OVERRIDE requires an unnecessary `:` in the URI #3573

Open anoadragon453 opened 2 months ago

anoadragon453 commented 2 months ago

First Check

What is the issue you are experiencing?

The new POSTGRES_URL_OVERRIDE environment variable requires that a colon must be present to separate the postgres database username and password fields:

https://github.com/mealie-recipes/mealie/blob/53a1f045622da441cbd80a7e5614c62231cd8082/mealie/core/settings/db_providers.py#L55-L57

However, if one is not using a password to connect to their postgres database (for instance, if they are using peer authentication), then they should be able to omit the password and the colon altogether. See this portion of the libpq documentation:

postgresql://[userspec@][hostspec][/dbname][?paramspec]

where userspec is:

user[:password]

In my case, I set my connection string to the following in order to get mealie to connect to my database:

POSTGRES_URL_OVERRIDE="postgresql://mealie:@/mealie?host=/run/postgresql";

Yet it should be possible to provide the following instead:

POSTGRES_URL_OVERRIDE="postgresql://mealie@/mealie?host=/run/postgresql";

note the lack of : between postgresql://mealie and @.

Steps to Reproduce

1) Set DB_ENGINE=postgres and POSTGRES_URL_OVERRIDE=postgresql://mealie@/mealie?host=/run/postgresql environment variables. 2) See mealie fail to start up due to being unable to extract the password. This causes a runtime exception (instead of being handled gracefully).

Please provide relevant logs

May 07 23:26:19 plonkie systemd[1]: Starting Mealie, a self hosted recipe manager and meal planner...
May 07 23:26:22 plonkie init_db[952]: Traceback (most recent call last):
May 07 23:26:22 plonkie init_db[952]:   File "/nix/store/lpi16513bai8kg2bd841745vzk72475x-python3-3.11.9/lib/python3.11/logging/config.py", line 573, in configure
May 07 23:26:22 plonkie init_db[952]:     handler = self.configure_handler(handlers[name])
May 07 23:26:22 plonkie init_db[952]:               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
May 07 23:26:22 plonkie init_db[952]:   File "/nix/store/lpi16513bai8kg2bd841745vzk72475x-python3-3.11.9/lib/python3.11/logging/config.py", line 757, in configure_handler
May 07 23:26:22 plonkie init_db[952]:     result = factory(**kwargs)
May 07 23:26:22 plonkie init_db[952]:              ^^^^^^^^^^^^^^^^^
May 07 23:26:22 plonkie init_db[952]:   File "/nix/store/lpi16513bai8kg2bd841745vzk72475x-python3-3.11.9/lib/python3.11/logging/handlers.py", line 155, in __init__
May 07 23:26:22 plonkie init_db[952]:     BaseRotatingHandler.__init__(self, filename, mode, encoding=encoding,
May 07 23:26:22 plonkie init_db[952]:   File "/nix/store/lpi16513bai8kg2bd841745vzk72475x-python3-3.11.9/lib/python3.11/logging/handlers.py", line 58, in __init__
May 07 23:26:22 plonkie init_db[952]:     logging.FileHandler.__init__(self, filename, mode=mode,
May 07 23:26:22 plonkie init_db[952]:   File "/nix/store/lpi16513bai8kg2bd841745vzk72475x-python3-3.11.9/lib/python3.11/logging/__init__.py", line 1181, in __init__
May 07 23:26:22 plonkie init_db[952]:     StreamHandler.__init__(self, self._open())
May 07 23:26:22 plonkie init_db[952]:                                  ^^^^^^^^^^^^
May 07 23:26:22 plonkie init_db[952]:   File "/nix/store/lpi16513bai8kg2bd841745vzk72475x-python3-3.11.9/lib/python3.11/logging/__init__.py", line 1213, in _open
May 07 23:26:22 plonkie init_db[952]:     return open_func(self.baseFilename, self.mode,
May 07 23:26:22 plonkie init_db[952]:            ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
May 07 23:26:22 plonkie init_db[952]: PermissionError: [Errno 13] Permission denied: '/mnt/storagebox/mealie/mealie.log'
May 07 23:26:22 plonkie init_db[952]: The above exception was the direct cause of the following exception:
May 07 23:26:22 plonkie init_db[952]: Traceback (most recent call last):
May 07 23:26:22 plonkie init_db[952]:   File "/nix/store/0qx0wf0pr2w8fiilnlxh26sp22y347pq-python3.11-mealie-1.5.1/lib/python3.11/site-packages/mealie/scripts/install_model.py", line 3, in <module>
May 07 23:26:22 plonkie init_db[952]:     from mealie.services.parser_services import crfpp
May 07 23:26:22 plonkie init_db[952]:   File "/nix/store/0qx0wf0pr2w8fiilnlxh26sp22y347pq-python3.11-mealie-1.5.1/lib/python3.11/site-packages/mealie/services/parser_services/__init__.py", line 1, in <module>
May 07 23:26:22 plonkie init_db[952]:     from .ingredient_parser import *
May 07 23:26:22 plonkie init_db[952]:   File "/nix/store/0qx0wf0pr2w8fiilnlxh26sp22y347pq-python3.11-mealie-1.5.1/lib/python3.11/site-packages/mealie/services/parser_services/ingredient_parser.py", line 10, in <module>
May 07 23:26:22 plonkie init_db[952]:     from mealie.db.models.recipe.ingredient import IngredientFoodModel, IngredientUnitModel
May 07 23:26:22 plonkie init_db[952]:   File "/nix/store/0qx0wf0pr2w8fiilnlxh26sp22y347pq-python3.11-mealie-1.5.1/lib/python3.11/site-packages/mealie/db/models/recipe/__init__.py", line 3, in <module>
May 07 23:26:22 plonkie init_db[952]:     from .category import *
May 07 23:26:22 plonkie init_db[952]:   File "/nix/store/0qx0wf0pr2w8fiilnlxh26sp22y347pq-python3.11-mealie-1.5.1/lib/python3.11/site-packages/mealie/db/models/recipe/category.py", line 16, in <module>
May 07 23:26:22 plonkie init_db[952]:     logger = root_logger.get_logger()
May 07 23:26:22 plonkie init_db[952]:              ^^^^^^^^^^^^^^^^^^^^^^^^
May 07 23:26:22 plonkie init_db[952]:   File "/nix/store/0qx0wf0pr2w8fiilnlxh26sp22y347pq-python3.11-mealie-1.5.1/lib/python3.11/site-packages/mealie/core/root_logger.py", line 37, in get_logger
May 07 23:26:22 plonkie init_db[952]:     __root_logger = configured_logger(
May 07 23:26:22 plonkie init_db[952]:                     ^^^^^^^^^^^^^^^^^^
May 07 23:26:22 plonkie init_db[952]:   File "/nix/store/0qx0wf0pr2w8fiilnlxh26sp22y347pq-python3.11-mealie-1.5.1/lib/python3.11/site-packages/mealie/core/logger/config.py", line 66, in configured_logger
May 07 23:26:22 plonkie init_db[952]:     logging_config.dictConfig(config=__conf)
May 07 23:26:22 plonkie init_db[952]:   File "/nix/store/lpi16513bai8kg2bd841745vzk72475x-python3-3.11.9/lib/python3.11/logging/config.py", line 823, in dictConfig
May 07 23:26:22 plonkie init_db[952]:     dictConfigClass(config).configure()
May 07 23:26:22 plonkie init_db[952]:   File "/nix/store/lpi16513bai8kg2bd841745vzk72475x-python3-3.11.9/lib/python3.11/logging/config.py", line 580, in configure
May 07 23:26:22 plonkie init_db[952]:     raise ValueError('Unable to configure handler '
May 07 23:26:22 plonkie init_db[952]: ValueError: Unable to configure handler 'file'
May 07 23:26:24 plonkie init_db[1523]: Traceback (most recent call last):
May 07 23:26:24 plonkie init_db[1523]:   File "/nix/store/0qx0wf0pr2w8fiilnlxh26sp22y347pq-python3.11-mealie-1.5.1/lib/python3.11/site-packages/mealie/db/init_db.py", line 13, in <module>
May 07 23:26:24 plonkie init_db[1523]:     from mealie.db.db_setup import session_context
May 07 23:26:24 plonkie init_db[1523]:   File "/nix/store/0qx0wf0pr2w8fiilnlxh26sp22y347pq-python3.11-mealie-1.5.1/lib/python3.11/site-packages/mealie/db/db_setup.py", line 25, in <module>
May 07 23:26:24 plonkie init_db[1523]:     SessionLocal, engine = sql_global_init(settings.DB_URL)  # type: ignore
May 07 23:26:24 plonkie init_db[1523]:                                            ^^^^^^^^^^^^^^^
May 07 23:26:24 plonkie init_db[1523]:   File "/nix/store/0qx0wf0pr2w8fiilnlxh26sp22y347pq-python3.11-mealie-1.5.1/lib/python3.11/site-packages/mealie/core/settings/settings.py", line 91, in DB_URL
May 07 23:26:24 plonkie init_db[1523]:     return self.DB_PROVIDER.db_url if self.DB_PROVIDER else None
May 07 23:26:24 plonkie init_db[1523]:            ^^^^^^^^^^^^^^^^^^^^^^^
May 07 23:26:24 plonkie init_db[1523]:   File "/nix/store/0qx0wf0pr2w8fiilnlxh26sp22y347pq-python3.11-mealie-1.5.1/lib/python3.11/site-packages/mealie/core/settings/db_providers.py", line 55, in db_url
May 07 23:26:24 plonkie init_db[1523]:     remainder = remainder.split(":", 1)[1]
May 07 23:26:24 plonkie init_db[1523]:                 ~~~~~~~~~~~~~~~~~~~~~~~^^^
May 07 23:26:24 plonkie init_db[1523]: IndexError: list index out of range
May 07 23:26:24 plonkie systemd[1]: mealie.service: Control process exited, code=exited, status=1/FAILURE
May 07 23:26:24 plonkie systemd[1]: mealie.service: Failed with result 'exit-code'.
May 07 23:26:24 plonkie systemd[1]: Failed to start Mealie, a self hosted recipe manager and meal planner.

Mealie Version

1.5.1

Deployment

Other (please specify below)

Additional Deployment Details

NixOS

boc-the-git commented 1 month ago

Seems reasonable, thanks for providing the docs reference!

You seem to have a good handle on this @anoadragon453, would you like to raise the pull request for the change? 🙏