Skip to content

Commit 1f41812

Browse files
authored
Merge pull request #200 from geoffrey-eisenbarth/main
Add checks for depreciated attributes.
2 parents d7262b6 + 6f1bd9c commit 1f41812

File tree

3 files changed

+25
-14
lines changed

3 files changed

+25
-14
lines changed

.github/workflows/continuous-deployment.yaml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -46,16 +46,16 @@ jobs:
4646
strategy:
4747
matrix:
4848
python: ['3.7', '3.8', '3.9', '3.10', '3.11']
49-
django: ['3.2', '4.2', '5.0']
49+
django: ['3.2', '4.2', '5.1']
5050
exclude:
5151
- python: '3.7'
5252
django: '4.2'
5353
- python: '3.7'
54-
django: '5.0'
54+
django: '5.1'
5555
- python: '3.8'
56-
django: '5.0'
56+
django: '5.1'
5757
- python: '3.9'
58-
django: '5.0'
58+
django: '5.1'
5959
steps:
6060
- name: Checkout
6161
uses: actions/checkout@v4

postgres_copy/managers.py

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,8 @@ def drop_constraints(self):
5353
logger.debug(f"Dropping constraints from {self.model.__name__}")
5454
with connection.schema_editor() as schema_editor:
5555
# Remove any "unique_together" constraints
56-
if self.model._meta.unique_together:
56+
# NOTE: "unique_together" may be deprecated in the future
57+
if getattr(self.model._meta, 'unique_together', False):
5758
logger.debug(
5859
"Dropping unique_together of {}".format(
5960
self.model._meta.unique_together
@@ -76,11 +77,12 @@ def drop_indexes(self):
7677
"""
7778
logger.debug(f"Dropping indexes from {self.model.__name__}")
7879
with connection.schema_editor() as schema_editor:
79-
# Remove any "index_together" constraints
80-
logger.debug(
81-
f"Dropping index_together of {self.model._meta.index_together}"
82-
)
83-
if self.model._meta.index_together:
80+
if getattr(self.model._meta, 'index_together', False):
81+
# Remove any "index_together" constraints
82+
# NOTE: "index_together has been removed from Django 5.1
83+
logger.debug(
84+
f"Dropping index_together of {self.model._meta.index_together}"
85+
)
8486
args = (self.model, self.model._meta.index_together, ())
8587
self.edit_schema(schema_editor, "alter_index_together", args)
8688

@@ -99,7 +101,8 @@ def restore_constraints(self):
99101
logger.debug(f"Adding constraints to {self.model.__name__}")
100102
with connection.schema_editor() as schema_editor:
101103
# Add any "unique_together" contraints from the database
102-
if self.model._meta.unique_together:
104+
# NOTE: "unique_together" may be deprecated in the future
105+
if getattr(self.model._meta, 'unique_together', False):
103106
logger.debug(
104107
"Adding unique_together of {}".format(
105108
self.model._meta.unique_together
@@ -122,8 +125,9 @@ def restore_indexes(self):
122125
"""
123126
logger.debug(f"Adding indexes to {self.model.__name__}")
124127
with connection.schema_editor() as schema_editor:
125-
# Add any "index_together" contraints to the database.
126-
if self.model._meta.index_together:
128+
if getattr(self.model._meta, 'index_together', False):
129+
# Add any "index_together" contraints to the database.
130+
# NOTE: "index_together has been removed from Django 5.1
127131
logger.debug(
128132
"Restoring index_together of {}".format(
129133
self.model._meta.index_together

tests/models.py

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import django
12
from django.db import models
23

34
from postgres_copy import CopyManager, CopyMapping
@@ -17,7 +18,13 @@ class MockObject(models.Model):
1718
class Meta:
1819
app_label = "tests"
1920
unique_together = ("name", "number")
20-
index_together = ("name", "number")
21+
22+
def __init__(self, *args, **kwargs):
23+
super().__init__(*args, **kwargs)
24+
if django.get_version() <= '5.1':
25+
self._meta.index_together = ("name", "number")
26+
else:
27+
self._meta.indexes = [models.Index(fields=["name", "number"])]
2128

2229
def copy_name_template(self):
2330
return 'upper("%(name)s")'

0 commit comments

Comments
 (0)