Use psycopg2 constants for isolation_level again (#6569)

This commit is contained in:
Bobbe 2024-02-25 23:46:57 +01:00 committed by GitHub
parent 2df0fd8a67
commit a3dc3bdbf4
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -571,6 +571,11 @@ db_options = db_config.get('OPTIONS', db_config.get('options', {}))
# Specific options for postgres backend # Specific options for postgres backend
if 'postgres' in db_engine: # pragma: no cover if 'postgres' in db_engine: # pragma: no cover
from psycopg2.extensions import (
ISOLATION_LEVEL_READ_COMMITTED,
ISOLATION_LEVEL_SERIALIZABLE,
)
# Connection timeout # Connection timeout
if 'connect_timeout' not in db_options: if 'connect_timeout' not in db_options:
# The DB server is in the same data center, it should not take very # The DB server is in the same data center, it should not take very
@ -634,7 +639,11 @@ if 'postgres' in db_engine: # pragma: no cover
serializable = get_boolean_setting( serializable = get_boolean_setting(
'INVENTREE_DB_ISOLATION_SERIALIZABLE', 'database.serializable', False 'INVENTREE_DB_ISOLATION_SERIALIZABLE', 'database.serializable', False
) )
db_options['isolation_level'] = 4 if serializable else 2 db_options['isolation_level'] = (
ISOLATION_LEVEL_SERIALIZABLE
if serializable
else ISOLATION_LEVEL_READ_COMMITTED
)
# Specific options for MySql / MariaDB backend # Specific options for MySql / MariaDB backend
elif 'mysql' in db_engine: # pragma: no cover elif 'mysql' in db_engine: # pragma: no cover