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

fix: audit log creation failure when a segment override is deleted #4829

Conversation

uinstinct
Copy link
Contributor

Thanks for submitting a PR! Please check the boxes below:

  • I have added information to docs/ if required so people know about the feature!
  • I have filled in the "Changes" section below?
  • I have filled in the "How did you test this code" section below?
  • I have used a Conventional Commit title for this Pull Request

closes #4828

Changes

instance is already deleted in the audit tasks while it is processed

this PR introduces a check to see if the instance exists before getting the environment from a non-existent object

How did you test this code?

As described in the issue

@uinstinct uinstinct requested a review from a team as a code owner November 12, 2024 13:46
@uinstinct uinstinct requested review from khvn26 and removed request for a team November 12, 2024 13:46
Copy link

vercel bot commented Nov 12, 2024

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

1 Skipped Deployment
Name Status Preview Comments Updated (UTC)
docs ⬜️ Ignored (Inspect) Visit Preview Nov 12, 2024 1:46pm

Copy link

vercel bot commented Nov 12, 2024

@uinstinct is attempting to deploy a commit to the Flagsmith Team on Vercel.

A member of the Team first needs to authorize it.

@github-actions github-actions bot added the api Issue related to the REST API label Nov 12, 2024
Copy link
Contributor

github-actions bot commented Nov 12, 2024

Uffizzi Preview deployment-58187 was deleted.

Comment on lines +92 to +94
environment = project = None
if instance.__class__.objects.filter(pk=instance.pk).exists():
environment, project = instance.get_environment_and_project()
Copy link
Member

@khvn26 khvn26 Nov 12, 2024

Choose a reason for hiding this comment

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

Thanks for the contribution, @uinstinct.

Two thoughts on the PR:

  1. Let's add a unit test that reproduces the bug/problem we're trying to fix here.
  2. An AuditLog instance lacking both project and environment relations is not valid. Even for a soft-deleted instance it shouldn't be a problem to retrieve them. I believe the problem is the way the related descriptors are used in FeatureSegment._get_environment and FeatureSegment._get_project implementations — they probably should account for soft-deleted instances. This should be clearer when we have a test with the actual reproducing code.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

on it

Copy link
Contributor

Choose a reason for hiding this comment

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

@uinstinct , just checking in to see when you think you'll have time to make the suggested changes?

Copy link
Contributor

Choose a reason for hiding this comment

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

@matthewelwell matthewelwell changed the base branch from main to fix/delete-segment-override-audit-log-creation December 6, 2024 11:11
@matthewelwell matthewelwell merged commit a5e1638 into Flagsmith:fix/delete-segment-override-audit-log-creation Dec 6, 2024
17 of 29 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
api Issue related to the REST API
Projects
None yet
Development

Successfully merging this pull request may close these issues.

AuditLog creation fails when a segment override is deleted
3 participants