Skip to content
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

Reset settings and fix for AppConfig.ready #128

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

ar0ne
Copy link

@ar0ne ar0ne commented Jan 11, 2024


name: Remove db calls from app ready hook
about: Submit a pull request for this project
assignees: fabiocaccamo


Describe your changes
First of all, Django "doesn't recommend" to run db calls in app ready hook (https://django.readthedocs.io/en/latest/ref/applications.html#django.apps.AppConfig.ready)

Instead, I'd like to explicitly ask users to set default values. For that they could use new dj-command:

python manage.py reset_extra_settings

Additionally, I added a button to "changelist" admin page.

Related issue
110
121

Checklist before requesting a review

  • I have performed a self-review of my code.
  • I have added tests for the proposed changes.
  • I have run the tests and there are not errors.

Copy link

codecov bot commented Jan 11, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 85.45%. Comparing base (fd891da) to head (7608c7e).
Report is 13 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main     #128      +/-   ##
==========================================
- Coverage   85.51%   85.45%   -0.07%     
==========================================
  Files          21       21              
  Lines         435      433       -2     
==========================================
- Hits          372      370       -2     
  Misses         63       63              
Flag Coverage Δ
unittests 85.45% <100.00%> (-0.07%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@fabiocaccamo fabiocaccamo self-requested a review January 11, 2024 13:54
@fabiocaccamo fabiocaccamo self-assigned this Jan 29, 2024
@fabiocaccamo fabiocaccamo added the enhancement New feature or request label Feb 12, 2024
@fabiocaccamo
Copy link
Owner

fabiocaccamo commented Feb 15, 2024

@ar0ne thank you for this PR, could you please split it into two smaller PRs, one for the fix and the other one for the admin integration (this one with a separate test module)?

@fabiocaccamo
Copy link
Owner

@ar0ne if you're still interested in working on this PR, please rebase it.

@ar0ne
Copy link
Author

ar0ne commented Feb 28, 2024

@fabiocaccamo hi, sure i hope to find some time on the weekend to address you comments

@fabiocaccamo fabiocaccamo assigned ar0ne and unassigned fabiocaccamo Mar 20, 2024
@ar0ne ar0ne force-pushed the reset_settings branch 3 times, most recently from f37c426 to 80206a7 Compare April 15, 2024 06:36
@@ -22,6 +22,7 @@ config and manage typed extra settings using just the django admin.
## Installation
- Run `pip install django-extra-settings`
- Add `extra_settings` to `settings.INSTALLED_APPS`
- Run `python manage.py reset_extra_settings`
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm pretty sure that running this command before migrate on first install will raise an Exception.

except (OperationalError, ProgrammingError):
pass

post_migrate.connect(Setting.set_defaults_from_settings, sender=self)
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Removing this line current tests fail.

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think that these tests are not enough and they don't cover well real usage, I try to explain better what I mean:

  • Tests pass because Setting.set_defaults_from_settings() is invoked manually (it should not)
  • Setting.set_defaults_from_settings() should be called automatically at some point at the begininng, but now calling it on app ready is discouraged.
  • Should improve the tests using more EXTRA_SETTINGS_DEFAULTS

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
Status: Todo
Development

Successfully merging this pull request may close these issues.

None yet

2 participants