TampereHacklab / mulysa

Mulysa member management for Hacklabs
GNU General Public License v3.0
6 stars 11 forks source link

Fix loading of local settings. #461

Open olmari opened 10 months ago

olmari commented 10 months ago

In drxf/settings.py move importing of local settings last thing that is done, this way any/all custom settings gets priority as they're loaded last.

Fixes: https://github.com/TampereHacklab/mulysa/issues/460

Signed-off-by: Sami Olmari sami@olmari.fi

tswfi commented 10 months ago

In my testing I don't see any difference on where the settings_local is loaded.

1) uncomment "ACCOUNT_IBAN": (ACCOUNT_IBAN, "IBAN of the association's bank account"), in CONSTANCE_CONFIG in settings.py 2) add ACCOUNT_IBAN = "ABC123" in settings_local.py (the default value in settings.py is "FI12 3456 789" 3) run ./manage.py shell_plus 4) in the shell run

from constance import config
print(config.ACCOUNT_IBAN)

and it prints out ABC123

But what I do see is that Constance has added an object for the setting even if I have never saved anything into it...

Constance.objects.get(key='ACCOUNT_IBAN').value

Looks like constance initializes its objects when the key is queried for the first time. It will take the default value configured at that point in time and then keeps it in the db.

olmari commented 10 months ago

That would conceptually match why local settings loading as last thing would make it also go...

Does generally things know local settings has priority? Or how else they know other than loading local settings in settings.py as last thing "overriding" anything set prior? Tho goes too deep into code for my knowledge anyways, kinda, sorta.

braaar commented 8 months ago

Just to clarify: Here is the sequence of operations we need:

  1. Load regular settings from settings.py
  2. Load regular settings from settings_local.py
  3. Consume the settings from settings.py and settings_local.py in the constance config.
  4. (if constance config is set in settings_local.py) load the settings_local constance config, which should consume values from settings and setting_local just like the original constance config

Local settings should always override, therefore we need to override the constance config in the end, if applicable