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

I wonder, why `post_setup()` wont' change setting values?

Open legshort opened this issue 7 years ago • 3 comments
trafficstars

I have an exmaple code but apparently, it's not supposed to work as mention here

# `SECRET_KEY not set` error occurs
class Dev(BaseSetting):
  SECRET_KEY = 'new_string'
  Env = 'Dev
  DEBUG = determine_debug()

def determine_debug():
  return 'Dev' == settings.Env:

New Trial

# `SECRET_KEY not set` error occurs
class Dev(BaseSetting):
  SECRET_KEY = 'new_string'
  Env = 'Dev
    
  @classmethod
  def post_setup(cls):
    super().post_setup()
    cls.DEBUG = determine_debug()

Workaround

class Dev(BaseSetting):
  SECRET_KEY = 'new_string'
  Env = 'Dev
  
  @classmethod
  def post_setup(cls):
    super().post_setup()
    DEBUG = determine_debug()

    setattr(setting_module, 'DEBUG', DEBUG)

So I have to call setattr() manually, I think django-configurations is a great tool to manage django configuration so easily but I found a buggy defect out of sudden.

Anyone has a similar expreience?

legshort avatar Jan 25 '18 05:01 legshort

I have a similar complaint in issue #217.

bittner avatar Dec 10 '18 00:12 bittner

The documentation on Setup methods says:

Of course that won’t work for post_setup since that’s when the settings setup is already done.

Maybe it's the setup() method you need to use. Can you try?

bittner avatar Dec 12 '18 10:12 bittner

I think I already tried that one before but it seems the docs was updated since I opened this issue. Perhaps I can try with pre_setup(), however, that time I'm pretty sure that I have tried all kinds of methods that I can try.

Actually, now I changed the way I use django-configurations so that I wouldn't need to override setting like that anymore.

Thanks for your replay!!

legshort avatar Dec 12 '18 13:12 legshort