Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

DATABASE_URL doesn't support custom backends when underscores in engine part #202

Open
fdobrovolny opened this issue Nov 5, 2018 · 2 comments
Labels
bug Something isn't working

Comments

@fdobrovolny
Copy link

This works as expected:

>>> Env.db_url_config("custom.backend://user:password@example.com:5430/database")
{'NAME': 'database', 'USER': 'user', 'PASSWORD': 'password', 'HOST': 'example.com',
'PORT': 5430, 'ENGINE': 'custom.backend'}

Doesn't work:

>>> Env.db_url_config("some_custom.backend://user:password@example.com:5430/database")
/usr/local/lib/python3.7/site-packages/environ/environ.py:437: UserWarning: Engine 
not recognized from url:
{'NAME': 'ome_custom.backend://user:password@example.com:5430/database',
'USER': '', 'PASSWORD': '', 'HOST': '', 'PORT': '', 'ENGINE': ''}
  warnings.warn("Engine not recognized from url: {0}".format(config))
{}
>>> Env.db_url_config("custom.some_backend://user:password@example.com:5430/database")
/usr/local/lib/python3.7/site-packages/environ/environ.py:437: UserWarning: Engine
not recognized from url:
{'NAME': 'ustom.some_backend://user:password@example.com:5430/database', 
'USER': '', 'PASSWORD': '', 'HOST': '', 'PORT': '', 'ENGINE': ''}
  warnings.warn("Engine not recognized from url: {0}".format(config))
{}
@thiras
Copy link

thiras commented Feb 1, 2019

I confirm the bug under;

  • Python 3.6
  • Django 2.1.5

This might be a Py compatibility issue. I think url parsing fails at environ.py L#375

@loicteixeira
Copy link

Same issue here.

In the meantime, I went around the issue by monkey patching the Env class to add my own database scheme this way:

from environ import Env

Env.DB_SCHEMES['mybackend'] = 'some_custom.backend'
Env.db_url_config('mybackend://user:password@example.com:5430/database')
# {'NAME': 'database', 'USER': 'user', 'PASSWORD': 'password', 'HOST': 'example.com', 'PORT': 5430, 'ENGINE': 'some_custom.backend'}

For what is worth, I tried to make it a bit cleaner by subclassing Env to make my own subclass like so:

from environ import Env

class ExtendedEnv(Env):
    DB_SCHEMES = {
        **Env.DB_SCHEMES,
        'mybackend': 'some_custom.backend',
    }

However it doesn't work since Env.db_url_config uses Env.DB_SCHEMES and not cls.DB_SCHEMES so you have to modify Env.DB_SCHEMES in place 😢

tkdchen pushed a commit to tkdchen/django-environ that referenced this issue Oct 6, 2019
@sergeyklay sergeyklay added the bug Something isn't working label Sep 7, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

4 participants