Skip to content

Backend & celeryworker can't handle "complex" database passwords #269

Open
@Hultner

Description

@Hultner

Using a "complex" password containing any character that needs to be quoted/encoded crashes at import of backend/app/app/core/config.py at the assembly method https://github.com/tiangolo/full-stack-fastapi-postgresql/blob/490c554e23343eec0736b06e59b2108fdd057fdc/%7B%7Bcookiecutter.project_slug%7D%7D/backend/app/app/core/config.py#L43 when building DSN.

This is easily fixable by quoting the string before creating the DSN.

I patched my own instance like this:

--- a/{{cookiecutter.project_slug}}/backend/backend/app/app/core/config.py
+++ b/{{cookiecutter.project_slug}}/backend/backend/app/app/core/config.py
@@ -1,5 +1,6 @@
 import secrets
 from typing import Any, Dict, List, Optional, Union
+from urllib.parse import quote_plus

 from pydantic import AnyHttpUrl, BaseSettings, EmailStr, HttpUrl, PostgresDsn, validator

@@ -45,8 +46,8 @@ class Settings(BaseSettings):
             return v
         return PostgresDsn.build(
             scheme="postgresql",
-            user=values.get("POSTGRES_USER"),
-            password=values.get("POSTGRES_PASSWORD"),
+            user=quote_plus(values.get("POSTGRES_USER")),
+            password=quote_plus(values.get("POSTGRES_PASSWORD")),
             host=values.get("POSTGRES_SERVER"),
             path=f"/{values.get('POSTGRES_DB') or ''}",
         )

Before this patch the backend and celeryworker wouldn't start, after applying the patch everything seems to work fine and I can log into the application via the frontend ui.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions