Skip to content

Commit

Permalink
Small compat fixes around psycopg.sql
Browse files Browse the repository at this point in the history
  • Loading branch information
apollo13 committed May 12, 2022
1 parent 6519844 commit ccbef0f
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 4 deletions.
5 changes: 4 additions & 1 deletion django/db/backends/postgresql/operations.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,10 @@
from django.db.backends.utils import split_tzname_delta
from django.db.models.constants import OnConflict

from psycopg.sql import SQL, Literal
try:
from psycopg.sql import SQL, Literal
except ImportError:
from psycopg2.sql import SQL, Literal


class DatabaseOperations(BaseDatabaseOperations):
Expand Down
9 changes: 6 additions & 3 deletions django/db/backends/postgresql/schema.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,14 @@
import psycopg.sql

from django.db.backends.base.schema import BaseDatabaseSchemaEditor
from django.db.backends.ddl_references import IndexColumns
from django.db.backends.utils import strip_quotes

from .operations import compose

try:
import psycopg.sql as psycopg_sql
except ImportError:
import psycopg2.sql as psycopg_sql


class DatabaseSchemaEditor(BaseDatabaseSchemaEditor):

Expand Down Expand Up @@ -64,7 +67,7 @@ def execute(self, sql, params=()):
def quote_value(self, value):
if isinstance(value, str):
value = value.replace("%", "%%")
return psycopg.sql.quote(value)
return psycopg_sql.quote(value)

def _field_indexes_sql(self, model, field):
output = super()._field_indexes_sql(model, field)
Expand Down

0 comments on commit ccbef0f

Please sign in to comment.