-
-
Notifications
You must be signed in to change notification settings - Fork 316
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
default seems broken #192
Comments
This seems like a pretty serious issue, any chance of an update? |
i can see why you would expect that on first glance and i also could not find clear documentation :( what you are asking the software to do in the first two examples:
the the rules for turning (string) environment variables into booleans are documented. Since the value of your environment variable is "UA-123456-78" and not any of the
..., because i mentioned, that i think this makes sense and to illustrate an example:
i would not want my
this is important, because in this case i'd argue, there is a bug:
imho, this absolutely should return a boolean, when the environment variable is not set and the str value when it is, because that is explicitly what the code says :) |
It's really interesting. It was failing some weeks ago. But now I'm trying another time the same and it's not failing anymore. >>> import environ
>>> env = environ.Env()
>>> env.list('ALLOWED_HOSTS')
['localhost', '127.0.0.1']
>>> env.list('ALLOWED_HOSTS2', default=True)
True
>>> env.list('ALLOWED_HOSTS2', default=False)
False
>>> env('WRONG', default=True)
True
>>> env('WRONG', default=False)
False It's working as expected and I'm using the version 0.4.5. But it was failing 18 days ago at least. And was a pretty serious issue because a lot of projects rely on it and in one minor update, without any mention in the changelog the |
Same for me. Avoid using python True or False with the default parameter. |
@fdemmer Thanks for the feedback. I am not using django-environ anymore, please feel free to close. |
In case we expect a string from the environment variable and use the default parameter, should we use I got bitten by the 0.4.4 to 0.4.5 |
Hi @mbonnefoy thank you for posting the issue, v0.4.4...v0.4.5#diff-674c4b6fffd8c014550873f5a20c5149R286 This is the change from 0.4.4 to 0.4.5. @jbagot the issue is when Passing a boolean as default will cast the value to True if the key is found (bug), or the default itself if not (not a bug). @Tberdy is right, for now just avoid to use boolean as default in not boolean variables (that makes sense). I'll fix this issue as soon as possible (days, not months :D) |
Thanks @joke2k 🙂 |
I have been taking a look at this and I cannot see any benefit of this smart casting from default type. To have a variable that normally is supposed to contain for example an int but in case of no definition from the env you want to explicitly set it to None or False is something common, with the new version this is not possible anymore, you are killing the dynamic typing Python offers. If you want to force type casting for a specific variable you can currently do it like this:
this is ok, is working fine, but if you don't specify any type casting I think it shouldn't do it for you because is a feature. Why not revert this smart cast changes? |
Hi, I added a new option to disable the smart casting. The next release came soon with latest django/python support |
Hi there,
I've just updated from 0.4.4 to 0.4.5 and noticed a few unexpected behaviours with default. Presumably they relate to the casting changes that were introduced recently?
Cheers,
Matthieu
The text was updated successfully, but these errors were encountered: