django-constance
django-constance copied to clipboard
Refactor app and model
This MR reconsiders model status in the constance application. In current state model Constance does not belong to application constance - it belongs to application database. This have several issues:
-
Impossible to support content type and permission management via Django build-in functions. ConstanceConfig contains code to create them manually. Django does it automatically. Build-in cleaner of stale content types ./manage.py remove_stale_contenttypes --include-stale-apps removes manually created permissions and content types
-
https://github.com/jazzband/django-constance/issues/454 My PR fixes it
-
Different import errors which some users get. https://github.com/jazzband/django-constance/issues/452 Such issues would go away.
-
Enables Django build-in database routing to work by default https://github.com/jazzband/django-constance/issues/414 https://github.com/jazzband/django-constance/issues/376
What changes? Database table would always be created. It would be empty if DatabaseBackend is not used. Migration on new table would be automatic for new and old installations.
Django is carp enough for model to be attached to application. django-constance is rather old application and earlier it was not so strict.
This PR is draft. It is working example with code refactoring tested on 2 projects and postgres database. If my refactoring can be accepted I would add documentation, release notes about migration and will test on sqlite, mysql and postgres carefully.
I am open to discuss MR
Codecov Report
Merging #469 (3f4435e) into master (b6f8e2c) will increase coverage by
0.25%
. The diff coverage is82.14%
.
:exclamation: Current head 3f4435e differs from pull request most recent head 4ffa756. Consider uploading reports for the commit 4ffa756 to get more accurate results
@@ Coverage Diff @@
## master #469 +/- ##
==========================================
+ Coverage 83.19% 83.44% +0.25%
==========================================
Files 16 16
Lines 601 574 -27
Branches 120 115 -5
==========================================
- Hits 500 479 -21
+ Misses 67 63 -4
+ Partials 34 32 -2
Impacted Files | Coverage Δ | |
---|---|---|
constance/management/commands/constance.py | 92.72% <77.77%> (+5.84%) |
:arrow_up: |
constance/models.py | 81.25% <81.25%> (ø) |
|
constance/apps.py | 100.00% <100.00%> (+5.00%) |
:arrow_up: |
constance/backends/database/__init__.py | 58.69% <100.00%> (ø) |
|
constance/admin.py | 87.81% <0.00%> (-0.74%) |
:arrow_down: |
constance/checks.py | 80.00% <0.00%> (+6.08%) |
:arrow_up: |
:mega: We’re building smart automated test selection to slash your CI/CD build times. Learn more
Hello @Mogost ! Review please =)
I generally like the direction in which you are thinking. But I see a lot of risks in migrating old projects. Just for example, I found a place in my project where my migrations were dependent on Constance migrations like that:
class Migration(migrations.Migration):
dependencies = [
('database', '0001_initial'),
.....
Probably the right way would be not to delete migrations in database
but to create new migrations in constance
.
Also, the database application needs a final migration to clean up all traces and remove the table from the database. Otherwise, this table will stay there forever.
Also migrations and cleanup for permissions is needed.
If we do not migrate permissions constance users lost their perm configurations.
I also want to summon here @jezdez to review
Hello @Mogost ! Sorry for so long review fixes. Now everything is saved: table, permissions, content types.
@jazzband/django-constance Please help to review
@Mogost @camilonova Well, I fixed everything. Review finally please =)
Does this mean there's no more database backend for constance?
I upgraded from 2.9.1 and I'm unable to get it to work.
When I try to install django-constance[database]
I get:
WARNING: django-constance 3.1.0 does not provide the extra 'database'
When I try to run, I get:
from constance.backends.database.models import Constance ModuleNotFoundError: No module named 'constance.backends.database.models'; 'constance.backends.database' is not a package
@SpecialK118 Hello) install just via pip install django-constance
.
'constance.backends.database
' should be removed from INSTALLED_APPS
Changes are described in changelog