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

Soft deleting a ratelimit namespace causes an error if the same name is used again. #2869

Open
3 tasks done
perkinsjr opened this issue Feb 4, 2025 · 6 comments · May be fixed by #2872
Open
3 tasks done

Soft deleting a ratelimit namespace causes an error if the same name is used again. #2869

perkinsjr opened this issue Feb 4, 2025 · 6 comments · May be fixed by #2872
Labels
Bug Something isn't working

Comments

@perkinsjr
Copy link
Collaborator

Preliminary Checks

Reproduction / Replay Link (Optional)

No response

Issue Summary

As a user if someone deletes a namespace by accident from our ratelimit for example

user.delete

They are unable to create a new namespace with the name of user.delete when they attempt it they get:

{
    "code": "INTERNAL_SERVER_ERROR",
    "httpStatus": 500,
    "stack": "TRPCError: We are unable to create namspace. Please try again or contact support@unkey.dev\n    at (vc/edge/function:1030:252976)\n    at (vc/edge/function:1030:252400)\n    at (vc/edge/function:295:130122)\n    at (vc/edge/function:295:129531)\n    at (vc/edge/function:295:129531)\n    at (vc/edge/function:295:129531)\n    at (vc/edge/function:295:129841)\n    at (vc/edge/function:1040:13815)\n    at (vc/edge/function:1040:15263)",
    "path": "ratelimit.namespace.create"
}

We should allow recreation or allow restoration without our intervention

Steps to Reproduce

  1. delete namespace
  2. recreate namespace with same name
  3. error

Expected behavior

Allow for the same namespace to be used again after soft delete or gracefully allow for restoration.

Other information

No response

Screenshots

No response

Version info

N/A
@perkinsjr perkinsjr added Bug Something isn't working Needs Approval Needs approval from Unkey labels Feb 4, 2025
@harshsbhat
Copy link
Contributor

Can I give it a shot? if it is not planned internally

@chronark
Copy link
Collaborator

chronark commented Feb 5, 2025

@harshsbhat how do you plan to tackle it?

@harshsbhat
Copy link
Contributor

@chronark

Before inserting the namespace into the database we can check if the namespace is soft deleted or not.

const isSoftDeleted = await db.query.ratelimitNamespaces
        .findFirst({
          where: (table, { and, eq }) =>
            and(eq(table.name, input.name)),
        })
});

If it is soft deleted we can simply update the table for deleted_at = null and return the id of the same namespace.

This will allow the user to restore the namespace without manual intervention.

@harshsbhat
Copy link
Contributor

Also, I just checked we need to change the deleted_at = null for all the overrides as well. Let me know if this sounds a fair approach.

@harshsbhat harshsbhat linked a pull request Feb 6, 2025 that will close this issue
18 tasks
@harshsbhat
Copy link
Contributor

@chronark I have created a draft PR. There is also a video in that PR on how I have tackled this issue.

#2872

@perkinsjr perkinsjr removed the Needs Approval Needs approval from Unkey label Feb 13, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants