django-environ icon indicating copy to clipboard operation
django-environ copied to clipboard

filter/override query urls for db_url_config database "OPTIONS"

Open vchrisb opened this issue 9 years ago • 1 comments

I'm trying to use django-environ in my project that will run in a PaaS offering (Cloud Foundry) The DATABASE_URL is automatically populated with something similar to this: mysql://123456:[email protected]:3306/ad_123456?reconnect=true

django-environ does take the query string reconnect=true and populates database OPTIONS with reconnect=true. My problem is, that this option is not supported by mysqlclient and let to an exception: reconnect=true is an invalid keyword argument for this function django databases

Anyway to filter/override unsupported database OPTIONS? As a workaround I currently fallback to use dj-database-url which does not evaluate the query strings.

https://github.com/joke2k/django-environ/blob/develop/environ/environ.py#L374

if url.query:
    config_options = {}
    for k, v in urlparse.parse_qs(url.query).items():
        if k.upper() in cls._DB_BASE_OPTIONS:
            config.update({k.upper(): _cast_int(v[0])})
        else:
            config_options.update({k: _cast_int(v[0])})
    config['OPTIONS'] = config_options

vchrisb avatar Dec 07 '15 07:12 vchrisb

Actually we can add RECONNECT to Env._DB_BASE_OPTION but there is another problem, the value true isn't casted as boolean, couse _case_int() don't handle that.

joke2k avatar Dec 25 '15 16:12 joke2k