django-ltree icon indicating copy to clipboard operation
django-ltree copied to clipboard

♻️ REFACTOR check_database_backend_is_postgres

Open simkimsia opened this issue 2 years ago • 1 comments

  1. invert not any => all
  2. 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

simkimsia avatar Jun 10 '22 09:06 simkimsia

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>

CleanShot 2022-06-10 at 18 52 24

simkimsia avatar Jun 10 '22 11:06 simkimsia