django-ltree
django-ltree copied to clipboard
♻️ REFACTOR check_database_backend_is_postgres
- invert not any => all
- ensure that settings.DATABASES has default set
Why?
I use docker a lot. Sometimes I need to run commands like docker exec -it <container_running django> python manage.py <some_command_that_does_not_need_database>
so I will get error messages like
File "/usr/local/lib/python3.8/dist-packages/django_ltree/checks.py", line 11, in check_database_backend_is_postgres
if not any(d in settings.DATABASES["default"]["ENGINE"] for d in valid_dbs):
File "/usr/local/lib/python3.8/dist-packages/django_ltree/checks.py", line 11, in <genexpr>
if not any(d in settings.DATABASES["default"]["ENGINE"] for d in valid_dbs):
KeyError: 'default'
So I like to have the check_database_backend_is_postgres only to do so when there's actually a default database set.
On top of that, i follow sourcery's recommendations to refactor any => all
I have tested my own fork locally and it works without any issue when I run a docker exec -it <container_running django> python manage.py <some_command_that_does_not_need_database>