mirror of
https://github.com/ansible/awx.git
synced 2026-05-06 08:57:35 -02:30
Merge pull request #11945 from fosterseth/fix_create_partition_already_exists_error
Handle error for create_partition
This commit is contained in:
@@ -21,7 +21,7 @@ from django.core.exceptions import ObjectDoesNotExist, FieldDoesNotExist
|
|||||||
from django.utils.dateparse import parse_datetime
|
from django.utils.dateparse import parse_datetime
|
||||||
from django.utils.translation import gettext_lazy as _
|
from django.utils.translation import gettext_lazy as _
|
||||||
from django.utils.functional import cached_property
|
from django.utils.functional import cached_property
|
||||||
from django.db import connection
|
from django.db import connection, transaction, ProgrammingError
|
||||||
from django.db.models.fields.related import ForeignObjectRel, ManyToManyField
|
from django.db.models.fields.related import ForeignObjectRel, ManyToManyField
|
||||||
from django.db.models.fields.related_descriptors import ForwardManyToOneDescriptor, ManyToManyDescriptor
|
from django.db.models.fields.related_descriptors import ForwardManyToOneDescriptor, ManyToManyDescriptor
|
||||||
from django.db.models.query import QuerySet
|
from django.db.models.query import QuerySet
|
||||||
@@ -1141,12 +1141,16 @@ def create_partition(tblname, start=None, end=None, partition_label=None, minute
|
|||||||
else:
|
else:
|
||||||
partition_label = start.strftime('%Y%m%d_%H')
|
partition_label = start.strftime('%Y%m%d_%H')
|
||||||
|
|
||||||
with connection.cursor() as cursor:
|
try:
|
||||||
cursor.execute(
|
with transaction.atomic():
|
||||||
f'CREATE TABLE IF NOT EXISTS {tblname}_{partition_label} '
|
with connection.cursor() as cursor:
|
||||||
f'PARTITION OF {tblname} '
|
cursor.execute(
|
||||||
f'FOR VALUES FROM (\'{start_timestamp}\') to (\'{end_timestamp}\');'
|
f'CREATE TABLE IF NOT EXISTS {tblname}_{partition_label} '
|
||||||
)
|
f'PARTITION OF {tblname} '
|
||||||
|
f'FOR VALUES FROM (\'{start_timestamp}\') to (\'{end_timestamp}\');'
|
||||||
|
)
|
||||||
|
except ProgrammingError as e:
|
||||||
|
logger.debug(f'Caught known error due to existing partition: {e}')
|
||||||
|
|
||||||
|
|
||||||
def cleanup_new_process(func):
|
def cleanup_new_process(func):
|
||||||
|
|||||||
Reference in New Issue
Block a user