Skip to content

Commit

Permalink
Provide a dedicated function to return postgresql driver
Browse files Browse the repository at this point in the history
  • Loading branch information
sergeyklay committed Jun 15, 2022
1 parent 4948a02 commit 27fcdc3
Showing 1 changed file with 12 additions and 7 deletions.
19 changes: 12 additions & 7 deletions environ/compat.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,20 +25,21 @@
class ImproperlyConfigured(Exception):
pass

# back compatibility with django postgresql package
if DJANGO_VERSION is not None and DJANGO_VERSION < (2, 0):
DJANGO_POSTGRES = 'django.db.backends.postgresql_psycopg2'
else:
# https://docs.djangoproject.com/en/2.0/releases/2.0/#id1
DJANGO_POSTGRES = 'django.db.backends.postgresql'

# back compatibility with redis_cache package
if find_loader('redis_cache'):
REDIS_DRIVER = 'redis_cache.RedisCache'
else:
REDIS_DRIVER = 'django_redis.cache.RedisCache'


def choose_postgres_driver():
"""Backward compatibility for postgresql driver."""
old_django = DJANGO_VERSION is not None and DJANGO_VERSION < (2, 0)
if old_django:
return 'django.db.backends.postgresql_psycopg2'
return 'django.db.backends.postgresql'


def choose_pymemcache_driver():
"""Backward compatibility for pymemcache."""
old_django = DJANGO_VERSION is not None and DJANGO_VERSION < (3, 2)
Expand All @@ -49,4 +50,8 @@ def choose_pymemcache_driver():
return 'django.core.cache.backends.memcached.PyMemcacheCache'


DJANGO_POSTGRES = choose_postgres_driver()
"""The name of the PostgreSQL driver."""

PYMEMCACHE_DRIVER = choose_pymemcache_driver()
"""The name of the Pymemcache driver."""

0 comments on commit 27fcdc3

Please sign in to comment.