Skip to content

Commit

Permalink
[FIX] - Delete function wasn't working (#3323)
Browse files Browse the repository at this point in the history
  • Loading branch information
Jsyro authored Nov 27, 2024
1 parent f070c58 commit e411c99
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 17 deletions.
20 changes: 11 additions & 9 deletions services/core-api/app/api/verifiable_credentials/manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -394,16 +394,18 @@ def __init__(self):
pass

@classmethod
def delete_any_unsuccessful_untp_push(cls, dry: bool = False) -> int:
records = PermitAmendmentOrgBookPublish.find_all_unpublished()
delete_count = 0

for record in records:
if dry:
def delete_any_unsuccessful_untp_push(cls, live: bool = False) -> int:
if not live:
records = PermitAmendmentOrgBookPublish.find_all_unpublished()
delete_count = 0
for record in records:
current_app.logger.info(f"would delete {record}")
else:
record.delete()
delete_count += 1
delete_count += 1
else:
current_app.logger.info(f"LIVE DELETE")
records = PermitAmendmentOrgBookPublish.delete_all_unpublished()
delete_count = records
db.session.commit()

return delete_count

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
from sqlalchemy.dialects.postgresql import UUID
from sqlalchemy.schema import FetchedValue
from sqlalchemy.sql import true
from sqlalchemy.sql import true as sqltrue
from sqlalchemy.sql.expression import ColumnOperators
from app.extensions import db
from typing import List
from app.api.utils.models_mixins import AuditMixin, Base
Expand Down Expand Up @@ -38,5 +39,11 @@ def find_by_unsigned_payload_hash(cls,
@classmethod
def find_all_unpublished(cls, *, unsafe: bool = False) -> List["PermitAmendmentOrgBookPublish"]:
query = cls.query.unbound_unsafe() if unsafe else cls.query
results: List["PermitAmendmentOrgBookPublish"] = query.filter().all()
return [r for r in results if r.publish_state is not True]
results = query.filter(cls.publish_state != True).all()
return results

@classmethod
def delete_all_unpublished(cls, *, unsafe: bool = False) -> int:
query = cls.query.unbound_unsafe() if unsafe else cls.query
results = query.filter(cls.publish_state != True).delete()
return results
10 changes: 5 additions & 5 deletions services/core-api/app/commands.py
Original file line number Diff line number Diff line change
Expand Up @@ -185,16 +185,16 @@ def push_untp_map_data_to_publisher():
print("celery job started: push_untp_map_data_to_publisher")

@app.cli.command('cleanup_untp_map_data_failures')
@click.argument('dry', required=False)
def cleanup_untp_map_data_failures(dry: bool = True):
@click.argument('live', required=False, default=False)
def cleanup_untp_map_data_failures(live: bool = False):
from app import auth
from app.api.verifiable_credentials.manager import (
VerifiableCredentialManager, )
auth.apply_security = False
with current_app.app_context():
if dry:
print(f"dry running delete, add `true` as first argument to actually delete")
result = VerifiableCredentialManager.delete_any_unsuccessful_untp_push(dry)
if not live:
print(f"dry running delete, add `false` as first argument to actually delete")
result = VerifiableCredentialManager.delete_any_unsuccessful_untp_push(live)

print(f"delete_any_unsuccessful_untp_push complete: delete_count={result}")

Expand Down

0 comments on commit e411c99

Please sign in to comment.