question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

default seems broken

See original GitHub issue

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?

# the key is in my env
In [3]: env('GOOGLE_ANALYTICS_KEY')
Out[3]: 'UA-123456-78'
# I should have used a string as default here
# but I would still expect these to return my key instead of False

In [4]: env('GOOGLE_ANALYTICS_KEY', default=False)
Out[4]: False

In [7]: env('GOOGLE_ANALYTICS_KEY', default=True)
Out[7]: False
# these ones work as expected

In [5]: env('GOOGLE_ANALYTICS_KEY', default='')
Out[5]: 'UA-123456-78'

In [6]: env('GOOGLE_ANALYTICS_KEY', default=None)
Out[6]: 'UA-123456-78'

Cheers, Matthieu

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Reactions:8
  • Comments:10 (3 by maintainers)

github_iconTop GitHub Comments

5reactions
pablobuenaposadacommented, Oct 30, 2019

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:

>>> import environ
>>> env = environ.Env()
>>> env('HOME')
'/Users/pablobuenaposada'
>>> env('HOME', cast=list)
['/Users/pablobuenaposada']

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?

2reactions
kozlekcommented, Feb 7, 2019

Same for me. Avoid using python True or False with the default parameter.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Default Windows Applications Broken - Microsoft Community
Whenever I try to open a Windows default app (photos, calculator, xbox game bar, microsoft store, etc.) it outputs the following error:.
Read more >
Restore Default View seems to be broken with floating windows
Hi,. i am used to using my IDE on two screens, wich is not entirely possible with rider, as far as I am...
Read more >
Theme is broken, keep reverting to default theme
I checked your site and it seems the current theme isn't Neve, it's Twenty Twenty One. The issue could be caused by some...
Read more >
apt package manager seems broken : r/pop_os - Reddit
When I try to install a new package on my Pop system, I get the following error: ❯ sudo apt install cheese Reading...
Read more >
Broken by default: why you should avoid most Dockerfile ...
A broken Docker image can lead to production outages, and building best-practices images is a lot harder than it seems. So don't just...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found