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

Handle soft deleted integrations #2217

Merged

Conversation

matthewelwell
Copy link
Contributor

@matthewelwell matthewelwell commented May 18, 2023

Changes

Refactors all integration models to upsert upsert if there is a soft deleted integration that already exists.

How did you test this code?

Added unit tests.

@vercel
Copy link

vercel bot commented May 18, 2023

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
docs ✅ Ready (Inspect) Visit Preview 💬 Add feedback May 25, 2023 9:19am
flagsmith-frontend-preview ✅ Ready (Inspect) Visit Preview 💬 Add feedback May 25, 2023 9:19am
flagsmith-frontend-staging ✅ Ready (Inspect) Visit Preview 💬 Add feedback May 25, 2023 9:19am

@github-actions
Copy link
Contributor

github-actions bot commented May 18, 2023

Uffizzi Preview deployment-25751 was deleted.

@@ -81,8 +81,8 @@ def slack_oauth_callback(self, request, environment_api_key):
code, self._get_slack_callback_url(environment_api_key)
)

SlackConfiguration.objects.update_or_create(
project=env.project, defaults={"api_token": bot_token}
SlackConfiguration.objects.all_with_deleted().update_or_create(
Copy link
Member

Choose a reason for hiding this comment

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

Should we create a test case that covers this?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I have fought with this for a long time to write a test that makes sense but, without refactoring all this code into a service layer, there is no easy (not hacky) way to test it. In doing this though, I realised that there is currently no way to delete a SlackConfiguration object anyway so, the way I see, the pragmatic solutions are:

  1. Keep the change I made just in case it happens in the future, but accept there is no test case to cover it
  2. Just revert this change so we are at least alerted via Sentry if it does happen

Copy link
Member

Choose a reason for hiding this comment

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

I think I prefer 2 because it should not happen under normal circumstances

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yep, ok, I've done that.

api/integrations/common/serializers.py Outdated Show resolved Hide resolved
@matthewelwell matthewelwell merged commit e28ee4e into main May 25, 2023
@matthewelwell matthewelwell deleted the 2129-soft-deleted-integration-key-can-not-be-added-again branch May 25, 2023 10:00
@matthewelwell matthewelwell linked an issue Jun 7, 2023 that may be closed by this pull request
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.

Soft deleted Integration key can not be added again
2 participants