agateblue / django-dynamic-preferences

Dynamic global and instance settings for your django project
https://django-dynamic-preferences.readthedocs.org/
BSD 3-Clause "New" or "Revised" License
350 stars 87 forks source link

preference_updated signal not fired when db_pref object is created #237

Closed felixrindt closed 2 years ago

felixrindt commented 3 years ago

In https://github.com/agateblue/django-dynamic-preferences/blob/4dd668f1b60523c6205b1df653501b8b7ca9023b/dynamic_preferences/managers.py#L155

the preference_update signal is only fired when the pref-object already exists in the DB, but it doesn't fire if the value is initially changed from the default setting. I do consider it a bug, because whether the object exists in the DB or the preference returns the default value should be opaque to the API user.

I'd suggest to also fire the signal in the except block over there, using the preference default as old_value for the signal.

agateblue commented 2 years ago

Closing, feel free to reopen and add more context if this still occurs.

felixrindt commented 2 years ago

Well the behavior hasn't changed. I'd respect your decision to not consider it an issue, although I do think the signal should fire in some way. (I don't see a button to repopen the issue.)

I was going to open a PR putting another signal send after the save() in create_db_pref() but I'm somewhat confused by this comment:

https://github.com/agateblue/django-dynamic-preferences/blob/e1813dfa72eefd7c6befe6a53ab94ceafaf4c1eb/dynamic_preferences/managers.py#L177

The raw_value is not passed to get_or_create. Is the comment outdated or am I missing something?