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

call core api delete from django delete #406

Merged
merged 4 commits into from
May 20, 2024

Conversation

rachaelcodes
Copy link
Contributor

@rachaelcodes rachaelcodes commented May 17, 2024

Context

Currently the frontend deletion of a file only deletes the file from the Django and S3 storage, but not the Elastic storage.

Changes proposed in this pull request

Deleting a file from the user interface propagates a call to core-api to delete the file and its chunks. If that API request fails, then the file will not delete from the Django database.

If the call to the API fails, the user will see this view:
Screenshot 2024-05-20 at 12 31 30

Guidance to review

Try deleting files from django.

Relevant links

https://technologyprogramme.atlassian.net/browse/REDBOX-256

Things to check

  • [ ] I have added any new ENV vars in all deployed environments
  • I have tested any code added or changed
  • I have run integration tests

@@ -195,7 +238,6 @@ def test_post_message_to_new_session(alice: User, client: Client, requests_mock:
assert response.status_code == HTTPStatus.FOUND
assert "Location" in response.headers
session_id = URL(response.url).parts[-2]
assert ChatMessage.objects.get(chat_history__id=session_id, role=ChatRoleEnum.user).text == "Are you there?"
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

hm not sure why this got deleted - will fix on Monday

if request.method == "POST":
logger.info("Removing document: %s", request.POST["doc_id"])
file.delete()
api = CoreApiClient(host=settings.CORE_API_HOST, port=settings.CORE_API_PORT)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this could be declared just once, maybe as a constant?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ultimately I'd like to inject it.

Copy link
Contributor

@252afh 252afh left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good to me, could we change the file deletion setting to seconds instead of days for future proofing please?

@@ -64,6 +69,7 @@ class File(UUIDPrimaryKeyBase, TimeStampedModel):
user = models.ForeignKey(User, on_delete=models.CASCADE)
original_file_name = models.TextField(max_length=2048, blank=True, null=True)
core_file_uuid = models.UUIDField(null=True)
expiry_date = models.DateField(default=get_default_expiry_date)
Copy link
Collaborator

@gecBurton gecBurton May 20, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

either:

  • this needs to be nullable or we will get an error on migration, or
  • we could compute this field on the fly from the created_at: datetime

?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hm something went wrong changing branch - that should be from a different ticket.

@@ -24,6 +24,7 @@
from yarl import URL

logger = logging.getLogger(__name__)
core_api = CoreApiClient(host=settings.CORE_API_HOST, port=settings.CORE_API_PORT)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🙏

Copy link
Collaborator

@gecBurton gecBurton left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

one RFC, otherwise LGTM

@rachaelcodes rachaelcodes merged commit 132a482 into main May 20, 2024
9 checks passed
@rachaelcodes rachaelcodes deleted the bugfix/REDBOX-256-delete-file-and-chunks branch May 20, 2024 14:42
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants