Skip to content

Support for dict as a cast argument #35

Closed

Description

@tadeoos

Hey,

I was wondering what are your thoughts about extending current functionality with a possible "cast as dict" feature.

In Django for example, the 'DATABASES' setting varies from deploy to production and it is quite nice and easy (although I admit, a little brute) to just keep the entire db dict as a string in .env file

This fix makes it possible to just do:

in .env:

DATABASES={'default': {'ENGINE': 'db.backend', 'NAME': '/absolute/path/to/your/db.sqlite3',}} 

and in settings.py:

DATABASES = config('DATABASES', cast=dict)

I've forked the repo and implemented the change (using literal_eval function) so am ready for PR.

What do you think?

Activity

  1. henriquebastos commented on Aug 7, 2017

    @henriquebastos
    Collaborator

    Can you share your code strategy? I feel this shouldn't be inside decouple, but could be a helper dictionary cast function like Csv.

    I have a personal preference for strategies like dj-database-url that converts an URL to a DATABASE dictionary. For quite some time I though about including it as a dependency. However this seems too specific for Django.

  2. heliomeiralins commented on Aug 8, 2017

    @heliomeiralins

    @henriquebastos he already implemented it here

    To be honest, storing a database as a dict looks really strange and it makes it harder to read the contents of the variable. Imagine someone changing it in a .env file, it wouldn't be that easy. I feel this shouldn't be in decouple too.

    You really should be using dj-database-url or multiple variables.

  3. tadeoos commented on Aug 8, 2017

    @tadeoos
    Author

    Actually I totally agree. Thanks for dj-database-url, haven't heard of it. Actually the requested feature is totally unnecessary since you can already obtain the desired behaviour by simply passing the literal_eval function as the cast argument. I checked it out afterwards and didn't closed the issue... Sorry

  4. henriquebastos commented on Aug 8, 2017

    @henriquebastos
    Collaborator
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions