Giter Club home page Giter Club logo

Comments (6)

girapa avatar girapa commented on June 23, 2024

Not sure I've understood clearly your issue, but I was running into "cached" .env variables myself and seems like there's a an override="False" set by default in read_env. Set it to True and it will override previously cached/saved environment variables.

Is that the issue you were encountering?

from django-environ.

dacotagh avatar dacotagh commented on June 23, 2024

Can't see override option of read_env. Do you mean overwrite?
No, it doesn't related to the problem.

Will try explain scenario:

I have settings.py with

env = environ.Env()
environ.Env.read_env('.env', overwrite = True)
KEY = env.int('KEY', 0)

.env file with

KEY=3

Now it is ok, KEY is equal to 3.

If I want to change KEY to e.g. 5, I will change it in .env file

KEY=5

Development django reloads (I've added watchdog on .env file).
Production version restared using killall -HUP uwsgi
And KEY becames 5, ok.

Now I need to reset KEY to initial value, and I try to change .env file:

#KEY=5

It is reloaded/restarted again.
But value doesn't changed to 0, it remains 5, because of values are in env variables.

Of course, I can kill/start server.
But it is not so suitable and can be long enough.

Of course, I can set KEY to initial value.
But it is not so comfortable if KEY have something not so trivial as initial value.

So I suppose to add special sign to use default value from settings.py

-KEY=5

will lead to 0.

from django-environ.

girapa avatar girapa commented on June 23, 2024

I see your use case now.
In that, from the docs I can see support for complex values, one of which is the ability to pass a dict. In your case, your best bet would be to pass a dict with your two values and then create some logic to set the value in your application.

from django-environ.

dacotagh avatar dacotagh commented on June 23, 2024

No, I think you don't catch.

I describe very common scenario that any developer encounter with while development stage with any values in .env file.
And none of specific action should be done with it.

Well, if it hard to understand, I will do a patch.

from django-environ.

pataquets avatar pataquets commented on June 23, 2024

@dacotagh Could you provide a real-world example why and where is this needed?
Look like to me that you're trying to solve the problem the wrong way. I mean, common practice (The Twelve-Factor App) is to redeploy every time a env var configuration change is done.

Case in point from Cloud Run revisions docs:

When you deploy to a service or change the configuration of a service, an immutable revision is created.

If the setting you're changing it's meant to be configured more often, you might be interested in some other configuration method (e.g. database-backed), such as Constance.

from django-environ.

dacotagh avatar dacotagh commented on June 23, 2024

No, you're talking about dynamic settings, but I'm talking about static settings and it's changes for testing purpose.

We have ordinal configuration: django application, development config (runserver + sqlite), production config (uwsgi + postgres).
three config files: settings.py, settings_dev.py, settings_pro.py with hundreds of variables.
Most of them are wrapped with environ.
We have several .env files for different instances.
Everything is ok.

Now I need to change some of these settings for testing purpose (it can be development configuration or production as well).

For example, we have SESSION_SECURITY_EXPIRE_AFTER variable.
It set as

SESSION_SECURITY_EXPIRE_AFTER=env.int('SESSION_SECURITY_WARN_AFTER', 356 * 24 * 60 * 60) # one year

for development configuration and

SESSION_SECURITY_EXPIRE_AFTER=env.int('SESSION_SECURITY_EXPIRE_AFTER', 8 * 60 * 60) # 8 hours

for production configuration

I want to change it to 30 seconds to test, so I add to .env file line

SESSION_SECURITY_EXPIRE_AFTER=30

django reloads application just like it does for any changes in python code.

After successful testing I want to change it back.
But neither removing this line from .env file, commenting or somewhat else do not work, because it remains 30.

So we have some strange situation - for any of changes or settings in python code I can change it forward and back easily, but for values in .env I can't do the same, because it persists in environ.

Before using Environ we used 'import local_settings.py' pattern and we haven't such problem.

from django-environ.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.