1
0
mirror of https://github.com/django/django.git synced 2024-12-22 09:05:43 +00:00

Refs #33308 -- Moved psycopg2 imports to the psycopg_any module.

This commit is contained in:
Florian Apolloner 2022-12-12 08:25:05 +01:00 committed by Mariusz Felisiak
parent c5ed884eab
commit 2ebfbd894e
13 changed files with 38 additions and 29 deletions

View File

@ -1,8 +1,7 @@
from psycopg2.extras import DateRange, DateTimeRange, DateTimeTZRange, NumericRange
from django.apps import AppConfig
from django.core.signals import setting_changed
from django.db import connections
from django.db.backends.postgresql.psycopg_any import RANGE_TYPES
from django.db.backends.signals import connection_created
from django.db.migrations.writer import MigrationWriter
from django.db.models import CharField, OrderBy, TextField
@ -21,8 +20,6 @@ from .lookups import (
from .serializers import RangeSerializer
from .signals import register_type_handlers
RANGE_TYPES = (DateRange, DateTimeRange, DateTimeTZRange, NumericRange)
def uninstall_if_needed(setting, value, enter, **kwargs):
"""

View File

@ -1,10 +1,14 @@
import datetime
import json
from psycopg2.extras import DateRange, DateTimeTZRange, NumericRange, Range
from django.contrib.postgres import forms, lookups
from django.db import models
from django.db.backends.postgresql.psycopg_any import (
DateRange,
DateTimeTZRange,
NumericRange,
Range,
)
from django.db.models.lookups import PostgresOperatorLookup
from .utils import AttributeSetter

View File

@ -1,7 +1,10 @@
from psycopg2.extras import DateRange, DateTimeTZRange, NumericRange
from django import forms
from django.core import exceptions
from django.db.backends.postgresql.psycopg_any import (
DateRange,
DateTimeTZRange,
NumericRange,
)
from django.forms.widgets import HiddenInput, MultiWidget
from django.utils.translation import gettext_lazy as _

View File

@ -1,9 +1,8 @@
import sys
from psycopg2 import errors
from django.core.exceptions import ImproperlyConfigured
from django.db.backends.base.creation import BaseDatabaseCreation
from django.db.backends.postgresql.psycopg_any import errors
from django.db.backends.utils import strip_quotes

View File

@ -1,11 +1,9 @@
import json
from functools import lru_cache, partial
from psycopg2.extras import Inet
from psycopg2.extras import Json as Jsonb
from django.conf import settings
from django.db.backends.base.operations import BaseDatabaseOperations
from django.db.backends.postgresql.psycopg_any import Inet, Jsonb
from django.db.backends.utils import split_tzname_delta
from django.db.models.constants import OnConflict

View File

@ -0,0 +1,6 @@
from psycopg2 import errors, extensions # NOQA
from psycopg2.extras import DateRange, DateTimeRange, DateTimeTZRange, Inet # NOQA
from psycopg2.extras import Json as Jsonb # NOQA
from psycopg2.extras import NumericRange, Range # NOQA
RANGE_TYPES = (DateRange, DateTimeRange, DateTimeTZRange, NumericRange)

View File

@ -1,7 +1,6 @@
import psycopg2
from django.db.backends.base.schema import BaseDatabaseSchemaEditor
from django.db.backends.ddl_references import IndexColumns
from django.db.backends.postgresql.psycopg_any import extensions
from django.db.backends.utils import strip_quotes
@ -52,7 +51,7 @@ class DatabaseSchemaEditor(BaseDatabaseSchemaEditor):
def quote_value(self, value):
if isinstance(value, str):
value = value.replace("%", "%%")
adapted = psycopg2.extensions.adapt(value)
adapted = extensions.adapt(value)
if hasattr(adapted, "encoding"):
adapted.encoding = "utf8"
# getquoted() returns a quoted bytestring of the adapted value.

View File

@ -9,12 +9,10 @@ from django.db.backends.base.creation import BaseDatabaseCreation
from django.test import SimpleTestCase
try:
import psycopg2 # NOQA
from django.db.backends.postgresql.psycopg_any import errors
except ImportError:
pass
else:
from psycopg2 import errors
from django.db.backends.postgresql.creation import DatabaseCreation

View File

@ -8,14 +8,18 @@ from django.test import TestCase
from django.test.utils import modify_settings
try:
from psycopg2.extras import DateRange, DateTimeRange, DateTimeTZRange, NumericRange
from django.contrib.postgres.fields import (
DateRangeField,
DateTimeRangeField,
DecimalRangeField,
IntegerRangeField,
)
from django.db.backends.postgresql.psycopg_any import (
DateRange,
DateTimeRange,
DateTimeTZRange,
NumericRange,
)
except ImportError:
pass

View File

@ -31,8 +31,6 @@ from .models import (
)
try:
from psycopg2.extras import NumericRange
from django.contrib.postgres.aggregates import ArrayAgg
from django.contrib.postgres.expressions import ArraySubquery
from django.contrib.postgres.fields import ArrayField
@ -42,6 +40,7 @@ try:
SplitArrayField,
SplitArrayWidget,
)
from django.db.backends.postgresql.psycopg_any import NumericRange
except ImportError:
pass

View File

@ -11,9 +11,9 @@ from .models import (
)
try:
from psycopg2.extras import DateRange, NumericRange
from django.db.backends.postgresql.psycopg_any import DateRange, NumericRange
except ImportError:
pass # psycopg2 isn't installed.
pass # psycopg isn't installed.
class BulkSaveTests(PostgreSQLTestCase):

View File

@ -25,14 +25,13 @@ from . import PostgreSQLTestCase
from .models import HotelReservation, IntegerArrayModel, RangesModel, Room, Scene
try:
from psycopg2.extras import DateRange, NumericRange
from django.contrib.postgres.constraints import ExclusionConstraint
from django.contrib.postgres.fields import (
DateTimeRangeField,
RangeBoundary,
RangeOperators,
)
from django.db.backends.postgresql.psycopg_any import DateRange, NumericRange
except ImportError:
pass

View File

@ -20,14 +20,17 @@ from .models import (
)
try:
from psycopg2.extras import DateRange, DateTimeTZRange, NumericRange
from django.contrib.postgres import fields as pg_fields
from django.contrib.postgres import forms as pg_forms
from django.contrib.postgres.validators import (
RangeMaxValueValidator,
RangeMinValueValidator,
)
from django.db.backends.postgresql.psycopg_any import (
DateRange,
DateTimeTZRange,
NumericRange,
)
except ImportError:
pass