Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[ISSUE-3728] IntegrityError update or delete on table users_user vi #227

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion djautotask/__init__.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# -*- coding: utf-8 -*-
VERSION = (1, 6, 4, 'final')
VERSION = (1, 6, 5, 'final')

# pragma: no cover
if VERSION[-1] != "final":
Expand Down
20 changes: 17 additions & 3 deletions djautotask/sync.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
from dateutil.parser import parse
from decimal import Decimal

from django.db import transaction, IntegrityError
from django.db import transaction, IntegrityError, DatabaseError
from django.db.models import Q
from django.utils import timezone

Expand Down Expand Up @@ -243,6 +243,7 @@ def get(self, results):
class Synchronizer:
lookup_key = 'id'
last_updated_field = 'lastActivityDate'
bulk_prune = True

def __init__(self, full=False, *args, **kwargs):
self.client = self.client_class(
Expand Down Expand Up @@ -450,8 +451,20 @@ def prune_stale_records(self, initial_ids, synced_ids):
len(stale_ids), self.model_class.__bases__[0].__name__,
)
)
delete_qset.delete()

if self.bulk_prune:
delete_qset.delete()
else:
for instance in delete_qset:
try:
instance.delete()
except IntegrityError as e:
logger.exception(
'A database error occurred while attempting to '
'delete {} records. Error: {}'.format(
self.model_class.__bases__[0].__name__,
e.__cause__
)
)
return deleted_count

def get_delete_qset(self, stale_ids):
Expand Down Expand Up @@ -1836,6 +1849,7 @@ class ResourceSynchronizer(Synchronizer):
client_class = api.ResourcesAPIClient
model_class = models.ResourceTracker
last_updated_field = None
bulk_prune = False

related_meta = {
'licenseType': (models.LicenseType, 'license_type'),
Expand Down
Loading