Skip to content

Remove active scope in add-on purchase lookup for SM

What does this MR do and why?

Part of https://gitlab.com/gitlab-org/gitlab/-/issues/426733+

Prior to this change, when there was an existing add-on purchase record (GitlabSubscriptions::AddOnPurchase) for the SM instance (namespace is nil) and that record is expired, the license data sync would fail. This was because the record can't be found because the lookup for the add-on purchase was looking for a not expired record by using the active scope. As a result a new add-on purchase record was attempted to be created which would then fail due to the uniqueness validation of the subscription_add_on_id scoped to namespace_id.

In this change, the active record is removed to allow finding the add-on purchase record and updating it regardless of being active or expired.

How to set up and validate locally

With this MR's branch checked out:

  1. CustomersDot: Enable the purchase_code_suggestions feature flag for your CustomersDot instance.
  2. Zuora: Create a new Online Cloud subscription with a couple of Code Suggestions seats (example subscription).
  3. CustomersDot: Wait for the callout to process.
  4. CustomersDot: Copy the activation code from the email sent by the callout.
  5. GitLab: Active your GitLab instance with the activation code.
  6. GitLab: Open the rails console..
  7. GitLab: Load the last GitlabSubscriptions::AddOnPurchase record (it should belong to your subscription): add_on_purchase = GitlabSubscriptions::AddOnPurchase.last
  8. GitLab: Update the record manually to be expired: add_on_purchase.update(expires_at: Date.yesterday)
  9. GitLab: Manually trigger the license data sync on /admin/subscription.
  10. GitLab: Open /admin/sidekiq/retries and verify there's a retry for the SyncSeatLinkRequestWorker.
  11. GitLab: Verify the add-on purchase record wasn't updated: add_on_purchase.reload
  12. GitLab: Delete the retry entry on the Sidekiq retry page.

With this MR's branch checked out:

  1. GitLab: Manually trigger the license data sync on /admin/subscription.
  2. GitLab: Verify the add-on purchase record was updated this time: add_on_purchase.reload

MR acceptance checklist

This checklist encourages us to confirm any changes have been analyzed to reduce risks in quality, performance, reliability, security, and maintainability.

Edited by Corinna Gogolok

Merge request reports

Loading