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

♻️ REFACTOR check_database_backend_is_postgres #15

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

Conversation

simkimsia
Copy link

  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

1. invert not any => all
2. ensure that settigs.DATABASES has default set
@simkimsia
Copy link
Author

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

1 participant